From 63e9dbf146fd7a9642ad2ca87fd3d2984722dc48 Mon Sep 17 00:00:00 2001 From: Gavin Stone Date: Sat, 21 Jul 2018 00:43:35 +0100 Subject: [PATCH] Fix Get-User to select a unique name and suppress errors Get-User should not filter on Display Name as it may not be unique, change to UPN. All users don't necessarily have a mailbox so suppress situations where they don't --- HTMLReport.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/HTMLReport.ps1 b/HTMLReport.ps1 index 37c86c3..15150fa 100644 --- a/HTMLReport.ps1 +++ b/HTMLReport.ps1 @@ -550,11 +550,11 @@ Foreach ($User in $AllUsers) $UPN = $User.UserPrincipalName $UserLicenses = ($NewObject02 | Select-Object -ExpandProperty Licenses) -join ", " $Enabled = $User.AccountEnabled - $ResetPW = Get-User $User.DisplayName | Select-Object -ExpandProperty ResetPasswordOnNextLogon + $ResetPW = Get-User $User.UserPrincipalName | Select-Object -ExpandProperty ResetPasswordOnNextLogon If ($IncludeLastLogonTimestamp -eq $True) { - $LastLogon = Get-Mailbox $User.DisplayName | Get-MailboxStatistics -ErrorAction SilentlyContinue | Select-Object -ExpandProperty LastLogonTime -ErrorAction SilentlyContinue + $LastLogon = Get-Mailbox $User.DisplayName -ErrorAction SilentlyContinue | Get-MailboxStatistics -ErrorAction SilentlyContinue | Select-Object -ExpandProperty LastLogonTime -ErrorAction SilentlyContinue $obj = [PSCustomObject]@{ 'Name' = $Name 'UserPrincipalName' = $UPN