Jul 27 2016 11:31 PM
Jul 27 2016 11:31 PM
Hello All,
I need to extarct list of Contacts lets say abc.com from various DL's with in ORG. Once the list is extracted then modify the smtp address for these contacts from abc.com to xyz.com
Can some one let me know how best can this be achieved? or any one has any script already?
Thanks
Jul 27 2016 11:42 PM
Jul 27 2016 11:46 PM
Hello Maor,
1. Is it primary addresses you would like to change?
Answer: Yes
2. Would you like to keep the old ones as secondary addresse?
Answer is No
3. Is it an Exchange on-prem, Exchange online or hybrid?
Answer: It is Exchange Online.
Thanks for asking.,
Jul 27 2016 11:50 PM
Jul 27 2016 11:51 PM
Hi,
Created directly on Exchange Online.
Jul 27 2016 11:56 PM
Jul 28 2016 05:24 AM - edited Jul 28 2016 05:26 AM
SolutionTook a bit longer than expected, had to finish some obligations. Anyway, here goes:
Save the following code block as .ps1 (or download attachment) and run from Exchange online PoweShell.
It will ask you for the old domain, new domain, DL name and an output path for a log file.
A log will also be printed to your screen for your convenience, letting you know which contacts were modified and which were not since the address don't match (see print screen)
Please notice that this script works on mail-contacts as requested, so if you have mailboxes\mail-users - they will bot be modified. But that should be easy for you to change in the script (just change the "Set-MailContact" line to "Set-Mailbox" or "Set-MailUser" if required)
$DL = Read-Host -Prompt "Please Input DL Alias"; $OldDomain = "*"+(Read-Host -Prompt "Please Input domain to be converted"); $NewDomain = Read-Host -Prompt "Please Input designated new domain"; $OutPath = Read-Host -Prompt "Please input a full log output path, including file name with '.txt' ending"; $DLMembers = Get-DistributionGroupMember $DL; Foreach($Member in $DLMembers) { If($Member.PrimarySmtpAddress.toLower() -like $OldDomain.toLower()) { $NewAddress = $Member.PrimarySmtpAddress.toLower().Replace($OldDomain.toLower().trim("*"),$NewDomain); Set-MailContact $Member.Alias -WindowsEmailAddress $NewAddress; $Line = "Found mail-contact "+$Member.Alias+" , Replaced address "+$Member.PrimarySmtpAddress+" with the address $NewAddress"; $Output += @($Line); $Line; } If(!($Member.PrimarySmtpAddress.toLower() -like $OldDomain.toLower())){ $Line = $Line = "Found mail-contact "+$Member.Alias+" , but no changes made since primary address does not match domain to be converted"; $Output += @($Line); $Line; } } $Output|Out-File $OutPath;
Jul 28 2016 08:35 PM
Thank you so much for taking out your time and helping me.
Jul 28 2016 10:03 PM
Jul 28 2016 10:03 PM
Jul 28 2016 10:22 PM
Jul 28 2016 10:25 PM
That is correct.
query to see how many DL's are showing these contacts as members?
Jul 28 2016 11:39 PM
SolutionHere you go.
Same idea - save as .ps1 or download the attached file. Run from Exchange online PowerShell > input domain to search and wait for results.
$Domain = "*"+(Read-Host -Prompt "Please input domain to search for"); $Groups = Get-DistributionGroup -ResultSize Unlimited; Foreach($Group in $Groups) { $MembersWithDomain = Get-DistributionGroupMember $Group.Alias | Where {($_.PrimarySmtpAddress.toLower() -like $Domain.toLower()) -and ($_.RecipientType -eq "MailContact")}; If($MembersWithDomain){$GroupsWithDomain+=@($Group);$Count+=1} } Write-Host "Found "$Count" groups containing contacts with a primary address matching the domain"; Write-Host "Printing list to screen in 3 seconds"; Start-Sleep -S 3; $GroupsWithDomain;
Jul 28 2016 11:44 PM
Jul 28 2016 11:46 PM
Jul 28 2016 05:24 AM - edited Jul 28 2016 05:26 AM
SolutionTook a bit longer than expected, had to finish some obligations. Anyway, here goes:
Save the following code block as .ps1 (or download attachment) and run from Exchange online PoweShell.
It will ask you for the old domain, new domain, DL name and an output path for a log file.
A log will also be printed to your screen for your convenience, letting you know which contacts were modified and which were not since the address don't match (see print screen)
Please notice that this script works on mail-contacts as requested, so if you have mailboxes\mail-users - they will bot be modified. But that should be easy for you to change in the script (just change the "Set-MailContact" line to "Set-Mailbox" or "Set-MailUser" if required)
$DL = Read-Host -Prompt "Please Input DL Alias"; $OldDomain = "*"+(Read-Host -Prompt "Please Input domain to be converted"); $NewDomain = Read-Host -Prompt "Please Input designated new domain"; $OutPath = Read-Host -Prompt "Please input a full log output path, including file name with '.txt' ending"; $DLMembers = Get-DistributionGroupMember $DL; Foreach($Member in $DLMembers) { If($Member.PrimarySmtpAddress.toLower() -like $OldDomain.toLower()) { $NewAddress = $Member.PrimarySmtpAddress.toLower().Replace($OldDomain.toLower().trim("*"),$NewDomain); Set-MailContact $Member.Alias -WindowsEmailAddress $NewAddress; $Line = "Found mail-contact "+$Member.Alias+" , Replaced address "+$Member.PrimarySmtpAddress+" with the address $NewAddress"; $Output += @($Line); $Line; } If(!($Member.PrimarySmtpAddress.toLower() -like $OldDomain.toLower())){ $Line = $Line = "Found mail-contact "+$Member.Alias+" , but no changes made since primary address does not match domain to be converted"; $Output += @($Line); $Line; } } $Output|Out-File $OutPath;
Jul 28 2016 11:39 PM
SolutionHere you go.
Same idea - save as .ps1 or download the attached file. Run from Exchange online PowerShell > input domain to search and wait for results.
$Domain = "*"+(Read-Host -Prompt "Please input domain to search for"); $Groups = Get-DistributionGroup -ResultSize Unlimited; Foreach($Group in $Groups) { $MembersWithDomain = Get-DistributionGroupMember $Group.Alias | Where {($_.PrimarySmtpAddress.toLower() -like $Domain.toLower()) -and ($_.RecipientType -eq "MailContact")}; If($MembersWithDomain){$GroupsWithDomain+=@($Group);$Count+=1} } Write-Host "Found "$Count" groups containing contacts with a primary address matching the domain"; Write-Host "Printing list to screen in 3 seconds"; Start-Sleep -S 3; $GroupsWithDomain;