As part of a domain migration, there is a requirement that none of the domains being migrated can be referenced within a SIP or SMTP attribute in AzureAD or the “release” of the domain wont go through.
One of these attributes which can contain these addresses is the “proxyaddresses’ attribute in AD.
As a result, I worked out a script that will do the following.
- Get AD users who have a principal username of *@* – and select all their properties.
- Select their samaccountname, name and proxyaddresses where;
- The proxy address begins with “sip” or “smtp”
- And contains any of the listed domains
- Then join the addresses using the ; as a delimiter – this will allow you to delimit by the semicolon in excel should you need to.
- The final part of the script will export the results to a csv
The powershell script is provided below
#Get all users, select their samaccountname, name and proxy addresses that are prepended by SMTP or SIP and from one of the domains listed from lines 3-13.
#This will then export them to a csv at a location listed on line 16.
Get-ADUser -Filter { UserPrincipalName -like "*@*" } -Properties * | Select-Object samaccountName,Name, @{L = “ProxyAddresses”; E = {($_.ProxyAddresses | Where-Object {$_ -like "*smtp:*" -or $_ -like "*sip:*" `
-and $_ -like "*@notbad.sg*"`
-or $_ -like "*@notbad.com*"`
-or $_ -like "*@notbad.com.au*"`
-or $_ -like "*@notgood.com.au*"`
-or $_ -like "*@notgood2.com.au*"`
-or $_ -like "*@notgreat.com*"`
}) -join ';'}} | export-csv -append C:\Temp\TargetUsersInitialExport.csv