Postmaster Mailbox check

Let’s say you have 4 domains, domain1.com, domain2.com, domain3.com and domain4.com and you want to find out if you have postmaster mailboxes for any of the domains. You could just run these PowerShell commands

get-mailbox postmaster@domain1.com
get-mailbox postmaster@domain2.com
get-mailbox postmaster@domain3.com
get-mailbox postmaster@domain4.com

Or you could run the script below:

Script

# Postmaster check script

# first we need to export accepted domains to a CSV file

get-accepteddomain | export-csv c:\scripts\accepteddomains.csv

# Now we need to loop through this to find any Postmaster mailboxes in the Accepted Domains

$accepted = import-csv c:\scripts\accepteddomains.csv

foreach ($line in $accepted) {
$AD = $line.domainname
$postmaster = “postmaster@”+$line.domainname
$a = get-mailbox $postmaster -erroraction silentlycontinue
if (!$a) { Write-Host $postmaster” does not exist.” }
if ($a) { Write-Host $postmaster” does exist!” }
}

Which gives you this output:

[PS] C:\scripts>.\PostmasterCheck.ps1

postmaster@domain1.com does not exist.
postmaster@domain2.com does not exist.
postmaster@domain3.com does not exist.
postmaster@domain4.com does not exist.

So in my case I was missing all my domains. If they had existed, you would see this:

[PS] C:\scripts>.\PostmasterCheck.ps1

postmaster@domain1.com does exist!
postmaster@domain2.com does exist!
postmaster@domain3.com does exist!
postmaster@domain4.com does exist!

Hope you find this script useful.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s