Showing mailbox with different email domain alias

Hi People,

Can anyone please assist me with the powershell script to display the mailbox with additional alias or different authoritative domain ?

I got a script here from one of the Experts-Exchange author jjmck:

$domain = ""
Get-Mailbox -ResultSize unlimited | % {
	foreach ($address in $_.emailaddresses) {
		If (($address.type -eq "SMTP") -and (($address.Address.Split("@")[1] -eq $domain))) {
			$_.emailaddresses -= [Microsoft.Exchange.Data.ProxyAddress]("smtp:$($address.address)")
		}
	}
	Set-Mailbox $_.primarysmtpaddress -EmailAddresses $_.EmailAddresses
}

Open in new window


the script above was to change any email address that has different authoritative domain. what I need is to know how many records first then do the changes so that my manager know how many mailboxes affected.

so if anyone please can assist me in modifying those script above that'd be greatly appreciated.

Thanks
LVL 8
Senior IT System EngineerIT ProfessionalAsked:
Who is Participating?
 
Jamie McKillopConnect With a Mentor IT ManagerCommented:
Hello,

If you just want a count, this will do what you want:

$domain = ""
$i=0
Get-Mailbox -ResultSize unlimited | % {
	$j=0
	foreach ($address in $_.emailaddresses) {
		If (($address.type -eq "SMTP") -and (($address.Address.Split("@")[1] -eq $domain))) {
			#$_.emailaddresses -= [Microsoft.Exchange.Data.ProxyAddress]("smtp:$($address.address)")
			$j++
		}
	}
	if ($j -ne 0) {$i++}
	#Set-Mailbox $_.primarysmtpaddress -EmailAddresses $_.EmailAddresses
} 
$i

Open in new window


JJ
0
 
Senior IT System EngineerIT ProfessionalAuthor Commented:
thanks JJ,

I haven't tried that script yet as it is still on my way to the office. hopfully it should also displays the mailboxes with different mail domain as well.
0
 
Senior IT System EngineerIT ProfessionalAuthor Commented:
JJ, why it only shows the number 0 as the result ?
I have changed the $domain = "mydomain.com"
0
 
Senior IT System EngineerIT ProfessionalAuthor Commented:
Thanks !
0
All Courses

From novice to tech pro — start learning today.