I'm seeing output issues within the 'Not Found' column, even when DisplayName is not null it's marking mailbox as 'Mailbox Not Found'. Seems ok for the first 5 output lines until until it hits the first 'Cloud' DisplayName then it fills every cell with 'Mailbox Not Found' in the 'Not Found' column.
****if (($mb1 -eq 'No Cloud Mailbox') -and ($mb2 -eq 'No Onprem Mailbox')) { $mb3 = 'Mailbox Not Found' }****
Am I missing something? Any help would be appreciated.
#========
#Get date
#========
$date = Get-Date -format dd-MM-yy
#===========================
#Setting up global variables
#===========================
$allmbadinfo = @()
$mbadinfo = @()
$users = Get-Content D:\import\allrgs.txt
#=================
#Grab mailbox info
#=================
Foreach ($user in $users ) {
$mb1 = Get-RemoteMailbox $User
if ($mb1 -ne $null) { $mb1 = $mb1.DisplayName }
else {
$mb1 = 'No Cloud Mailbox' }
$mb2 = Get-Mailbox $User
if ($mb2 -ne $null) { $mb2 = $mb2.DisplayName }
else {
$mb2 = 'No Onprem Mailbox' }
if (($mb1 -eq 'No Cloud Mailbox') -and ($mb2 -eq 'No Onprem Mailbox')) { $mb3 = 'Mailbox Not Found' }
$imputlist = Write-Output $user
#================================================================================================
#Create new array object and populate information from variables, add table column names and data
#================================================================================================
$mbadinfo = New-Object PSObject
$mbadinfo | Add-Member -MemberType 'NoteProperty' -Name 'Cloud' -Value $mb1
$mbadinfo | Add-Member -MemberType 'NoteProperty' -Name 'Onprem' -Value $mb2
$mbadinfo | Add-Member -MemberType 'NoteProperty' -Name 'Not Found' -Value $mb3
$mbadinfo | Add-Member -MemberType 'NoteProperty' -Name 'Imput List' -Value $imputlist
$allmbadinfo += $mbadinfo
}
#======================
# Exporting data to csv
#======================
$allmbadinfo | Export-Csv D:\export\remotembxrgs-$date.csv -NoType -NoClobber
$mb1and$mb2get successfully set to null when no mailbox is found in all cases? Your condition should actually be$null -ne $mb1.