troubleshooting Question

Remove secondary email address

Avatar of suriyaehnop
suriyaehnopFlag for Malaysia asked on
ExchangePowershell
10 Comments1 Solution2190 ViewsLast Modified:
Function NewMailbox {

BEGIN {}

PROCESS {

New-Mailbox -Name $_.name -FirstName $_.firstname -LastName $_.lastname -Alias $_.alias `
-UserPrincipalName ($_.alias +'@contoso.com') -Database Mensa\SG4\DB4 -OrganizationalUnit $GetOrganization `
-Password ( ConvertTo-SecureString12345 -AsPlainText -Force) -ResetPasswordOnNextLogon:$false `
-ErrorVariable err | Out-Null



#Check AD Latency
do
{
 $mailbox = Get-Mailbox -Identity $_.alias -ErrorAction SilentlyContinue 
}
While ($mailbox -eq $null)

Set-User -Identity $_.alias -Company $_.Company -Title $_.title -Department $_.department `
-Office $_.office -Manager $_.manage

}

END {

do{

$_Infos = Get-User -Identity $_.alias
}
While ($_Infos.company -eq $null)

If ($_.company -eq 'Fabrikam'){ 
$1 = Get-Mailbox -Identity $_.alias
$2 = $1.emailaddresses | where {$_.ProxyAddressString -match "SMTP:$_.alias+'@fabrikam.com' "}
$2
$2
Set-Mailbox -Identity $_.alias -EmailAddresses $2 
}
}

}

Import-Csv C:\PS\CreateMailboxSapuraGroups.csv | NewMailbox
Function NewMailbox {

BEGIN {}

PROCESS {

New-Mailbox -Name $_.name -FirstName $_.firstname -LastName $_.lastname -Alias $_.alias `
-UserPrincipalName ($_.alias +'@contoso.com') -Database Mensa\SG4\DB4 -OrganizationalUnit $GetOrganization `
-Password ( ConvertTo-SecureString sapura2012 -AsPlainText -Force) -ResetPasswordOnNextLogon:$false `
-ErrorVariable err | Out-Null



#Check AD Latency
do
{
 $mailbox = Get-Mailbox -Identity $_.alias -ErrorAction SilentlyContinue 
}
While ($mailbox -eq $null)

Set-User -Identity $_.alias -Company $_.Company -Title $_.title -Department $_.department `
-Office $_.office -Manager $_.manage

}

END {

do{

$_Infos = Get-User -Identity $_.alias
}
While ($_Infos.company -eq $null)

If ($_.company -eq 'Fabrikam'){ 
$1 = Get-Mailbox -Identity $_.alias
$2 = $1.emailaddresses | where {$_.ProxyAddressString -match "SMTP:$_.alias+'@fabrikam.com' "}
$2
$2
Set-Mailbox -Identity $_.alias -EmailAddresses $2 -EmailAddressPolicyEnabled:$false
Set-Mailbox -Identity $_.alias -EmailAddressPolicyEnabled:$true
}
}

}

Import-Csv C:\PS\CreateMailboxSapuraGroups.csv | NewMailbox
We run on exchange 2007 have 1 default email address policy as @contoso.com and newly email address polify for staff with Company = Fabrikam will have address @fabrikam.com. I did tested that for user with fabrikam company will have final email address as @fabrikam (Primary) and @contoso(secondary). From EMC, I can delete secondary email address without uncheck "Update Email Addresses based email address policy".

I'm trying to use PowerShell to remove the secondary email address but failed. Attached is a script that i used.

I try with one user, it work but if i have bulk users, the email address will change for last user.

If I used second script it will failed end up with Email Address Policy must be disabled.

Please help
ASKER CERTIFIED SOLUTION
Jamie McKillop
IT Director

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 10 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros