Exchange PowerShell to check to see if a list of mailboxes exist.

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 = $
$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

#Export the CSV to a file
$Final | Export-csv C:tempResults_Users.csv

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: