Jump to content

Recommended Posts

Posted

I'm trying to migrate an O365 Domain to a new Tenant. It's going okay but before I can remove the domain from the old tenant I need to completely remove any references to the 'migrating' domain suffix. I've removed them all from most accounts using PowerShell and I was happy that things were going well. However I've hit a snag that's got me stumped for a couple of days. There are Proxy Email Addresses on some of my users. I can see which ones these are but I can't see any commands to remove them using PowerShell.

 

They're identified sing this:

 

Get-MsolUser -UserPrincipalName "username of user here" | select -ExpandProperty ProxyAddresses

 

This list reveals the email account that I need to remove however there is no Set-MSOLUser command to remove Proxy Email addresses.

 

I've looked in Exchange Online EAC to see if the account has an Exchange Mailbox which they do not. They do appear as a contact but the email address I want to remove is not visible in the properties. When checking within the O365 | Admin Center | Users | Active users the user's properties again do not show the email address that I want to remove.

 

Is there a PowerShell Command that will remove entries from the ProxyAddresses collection which is returned by the Get-MSOLUser command?

 

Regards,

 

Martin

Posted

[h=2]Unable to Remove or Delete ProxyAddresses / EmailAddresses from MSOLADUserobjects prior to Deleting a domain from O365[/h]

[h=3]Problem symptom:[/h]You are unable to delete a domain from O365 as there areemail addresses recorded for the MSOLUser within the ProxyAddresses field.

Problem users can be identified using the following PSextract:

Example domain name = abc.com

$UsersInError = Get-MsolUser -All | ?{$_.ProxyAddresses -like"*abc.com*"} | Sort-Object Displayname

These users correspond with Exchange Online | MailUserobjects. Iterate through each of the MSOLUser objects and foreach one, selectand remove each associated EmailAddress. Once removed, immediately add the sameaddress again.

This action appears to realign the values seen from MSOLUser–ProxyAddresses and MailUser EmailAddresses.

As each is processed they disappear from the problem usersidentified. This can be verified by running the check above again or by tryingto Delete the domain through the O365 Admin console.

$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationNameMicrosoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/-Credential $UserCredential-Authentication Basic-AllowRedirection

Import-PSSession $Session

Connect-MsolService

$UsersInError = Get-MsolUser -All | ?{$_.ProxyAddresses -like"*abc.com*"} | Sort-Object Displayname

#How many users are problem users

$UsersInError.Count

Write-Host

#Which users are in error

$UsersInError

Write-Host

foreach($UserInErrorin $UsersInError)

{

$User = Get-MailUser -Identity $UserInError.UserPrincipalName

Set-Mailbox-Identity $User -EmailAddresses= $User.EmailAddresses

foreach($address in$User.EmailAddresses)

{

Write-Host$address

Set-MailUser-Identity $User.DisplayName -EmailAddresses@{Remove=$address}

Set-MailUser-Identity $User.DisplayName -EmailAddresses@{Add=$address}

}

foreach($address in$User.EmailAddresses){$address}

}

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...