{"id":6119,"date":"2022-09-06T23:33:07","date_gmt":"2022-09-06T23:33:07","guid":{"rendered":"https:\/\/pariswells.com\/blog\/?p=6119"},"modified":"2022-11-23T21:44:02","modified_gmt":"2022-11-23T21:44:02","slug":"migrate-distribution-groups-and-members-between-365-tenants-and-settings","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/research\/migrate-distribution-groups-and-members-between-365-tenants-and-settings","title":{"rendered":"Migrate Distribution Groups and Members between 365 Tenants and settings"},"content":{"rendered":"\n<p>Alex has already done the hard work for this which works well<\/p>\n\n\n\n<p><a href=\"https:\/\/alexholmeset.blog\/2022\/01\/06\/exchange-online-distribution-list-migration-script\/\">Exchange Online Distribution List Migration Script | A blog about automation and technologies in the cloud (alexholmeset.blog)<\/a><\/p>\n\n\n\n<p>I changed the script as the Source tenant had multiple domains and also stoped 365 Groups with the same name causing issues<\/p>\n\n\n<div class=\"wp-block-wab-pastacode\">\n\t<div class=\"code-embed-wrapper\"> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">#Connect with source tenant<br\/>Connect-AzureAD<br\/><br\/>#Connect with destination tenant<br\/>Connect-ExchangeOnline<br\/><br\/><br\/>#Dist Groups list in array &quot;1&quot;,&quot;2&quot;<br\/>$DL = &quot;1&quot;,&quot;2&quot;<br\/><br\/><br\/>$ZSourceDomain = &quot;sourcedomain.com&quot;<br\/>$CSourceDomain = &quot;sourcedomain2.com&quot;<br\/>$DestinationDomain = &quot;destinationdomain3.com&quot;<br\/><br\/>foreach($D in $DL){<br\/>    <br\/>   $List = @()<br\/>   $List = Get-AzureADGroup -SearchString &quot;$D&quot;<br\/>   #Remove office 365 Groups with same name , using SPO as identifier<br\/>   $List = $list | ?{$_.proxyaddresses -match &#039;.*SPO.*&#039;}<br\/> <br\/>   $ZListMembers = @()<br\/>   $ZListMembers = Get-AzureADGroupMember -ObjectId $List.ObjectId | Where-Object {$_.UserPrincipalName -like &#039;*$ZSourceDomain&#039;}<br\/><br\/>   $ZListMembersUPN = @()<br\/>   $ZListMembersUPN = $ZListMembers.UserPrincipalName<br\/><br\/>   $CListMembers = @()<br\/>   $CListMembers = Get-AzureADGroupMember -ObjectId $List.ObjectId | Where-Object {$_.UserPrincipalName -like &#039;*$CSourceDomain&#039;}<br\/><br\/>   $CListMembersUPN = @()<br\/>   $CListMembersUPN = $CListMembers.UserPrincipalName<br\/><br\/><br\/>   New-DistributionGroup -Name $List.DisplayName -Description $List.Description -PrimarySmtpAddress $($List.MailNickName+&quot;@$DestinationDomain&quot;)<br\/>    <br\/>   foreach($ZListMemberUPN in $ZListMembersUPN){<br\/>   <br\/>               <br\/>        Add-DistributionGroupMember -Identity $List.DisplayName -Member $ZListMemberUPN.replace(&quot;$ZSourceDomain&quot;,&quot;$DestinationDomain&quot;)<br\/>        <br\/>        }<br\/>   <br\/>   foreach($CListMemberUPN in $CListMembersUPN){<br\/>   <br\/>               <br\/>        Add-DistributionGroupMember -Identity $List.DisplayName -Member $CListMemberUPN.replace(&quot;$CSourceDomain&quot;,&quot;$DestinationDomain&quot;)<br\/>        <br\/>        }<br\/>   <br\/>   <br\/>   <br\/><br\/>}<\/code><\/pre> <div class=\"code-embed-infos\"> <a href=\"https:\/\/github.com\/pariswells\/pariswells.com\/blob\/master\/copy-adzuread-Distribution-Lists+members.ps1\" title=\"See copy-adzuread-Distribution-Lists+members.ps1\" target=\"_blank\" class=\"code-embed-name\">copy-adzuread-Distribution-Lists+members.ps1<\/a> <a href=\"https:\/\/raw.github.com\/pariswells\/pariswells.com\/master\/copy-adzuread-Distribution-Lists+members.ps1\" title=\"Back to copy-adzuread-Distribution-Lists+members.ps1\" class=\"code-embed-raw\" target=\"_blank\">view raw<\/a> <\/div> <\/div><\/div>\n\n\n\n<p>Lets Export all Distribution settings from Source Tenant<\/p>\n\n\n<div class=\"wp-block-wab-pastacode\">\n\t<div class=\"code-embed-wrapper\"> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">#Connect with source tenant<br\/>Connect-ExchangeOnline<br\/><br\/>Get-DistributionGroup -RecipientTypeDetails MailUniversalDistributionGroup\u00a0|\u00a0Export-Csv -Path \u201cC:\\Temp\\dGroupsall.csv&quot;<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div><\/div>\n\n\n\n<p>Lets Import and Set what we need to the Destination Tenant<br>This script does RequireSenderAuthenticationEnabled ( Delivery Restrictions ) , Owner ( ManagedBy ) and MemberJoinRestriction. You can add any new ones you would like to set from the Sheet<\/p>\n\n\n<div class=\"wp-block-wab-pastacode\">\n\t<div class=\"code-embed-wrapper\"> <pre class=\"language-markup code-embed-pre line-numbers\"  data-start=\"1\" data-line-offset=\"0\"><code class=\"language-markup code-embed-code\">#Connect with destination tenant<br\/>Connect-ExchangeOnline<br\/><br\/>Import-Csv -Path &quot;C:\\Temp\\dGroupsall.csv&quot; | ForEach-Object {<br\/><br\/>#Lets do this one by one incase one fails it doesn\u2019t block other <br\/><br\/>\t#We need to convert the csv value to boolean to write to RequireSenderAuthenticationEnabled<br\/>\t[boolean] $RequireSenderAuthenticationEnabled = [system.convert]::toboolean($_.RequireSenderAuthenticationEnabled)<br\/>\tSet-DistributionGroup -Identity $_.Alias -RequireSenderAuthenticationEnabled $RequireSenderAuthenticationEnabled<br\/>\tSet-DistributionGroup -Identity $_.Alias -ManagedBy $_.ManagedBy <br\/>\tSet-DistributionGroup -Identity $_.Alias -MemberJoinRestriction $_.MemberJoinRestriction<br\/><br\/>}<\/code><\/pre> <div class=\"code-embed-infos\"> <\/div> <\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Alex has already done the hard work for this which works well Exchange Online Distribution List Migration Script | A blog about automation and technologies in the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3961,3958,2767,1418,3959,3960,576,3957,3962],"class_list":["post-6119","post","type-post","status-publish","format-standard","hentry","category-research","tag-boolean","tag-csv","tag-export","tag-import","tag-managedby","tag-memberjoinrestriction","tag-powershell","tag-requiresenderauthenticationenabled","tag-set-distributiongroup"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/6119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/comments?post=6119"}],"version-history":[{"count":6,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/6119\/revisions"}],"predecessor-version":[{"id":6395,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/6119\/revisions\/6395"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=6119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=6119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=6119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}