Forum Discussion
Help with Extracting list of contacts from specific domain
- Jul 28, 2016
Took 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 29, 2016
Here 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;
Hi,
Created directly on Exchange Online.
- DeletedJul 28, 2016Sure. Thanks
- Maor BrachaJul 28, 2016Brass Contributor
Took 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;
- DeletedJul 29, 2016
Thank you so much for taking out your time and helping me.