Scenario: You have a list of mailboxes that you want to check to see if a mailbox exists for each user. You want to output it to a table with a true or false.
Resolution: In my users.csv that I import, the column that I reference in this script has a column name labeled ‘name’. Note: If a mailbox doesn’t exist, it may display with “The operation couldn’t be performed because object couldn’t be found” in the Powershell window. The $Final variable will have a clean list with true or false for each mailbox.
#Create the Variable $final = @() #Import the CSV file with a column labeled 'name'. $1 = Import-CSV C:tempusers.csv #Loop it for each entry $1 | %{ $n = $_.name $r = [bool](get-mailbox "$n") #Build the Array $ServerObj = New-Object PSObject $ServerObj | Add-Member NoteProperty -Name "User" -Value $n $ServerObj | Add-Member NoteProperty -Name "Exists" -Value $r $Final += $ServerObj } #Display the Results $Final #Export the CSV to a file $Final | Export-csv C:tempResults_Users.csv