{"id":6124,"date":"2022-09-06T11:01:51","date_gmt":"2022-09-06T11:01:51","guid":{"rendered":"https:\/\/pariswells.com\/blog\/?p=6124"},"modified":"2022-11-23T00:57:18","modified_gmt":"2022-11-23T00:57:18","slug":"copy-azure-ad-security-groups-and-membership-one-tenancy-to-another","status":"publish","type":"post","link":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another","title":{"rendered":"Copy Azure AD Security Groups and Membership one Tenancy to Another"},"content":{"rendered":"<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\">#Sec Groups list in array &quot;1&quot;,&quot;2&quot;<br\/>$SG = &quot;GroupName&quot;<br\/><br\/>#To Grab All<br\/>#$SG = Get-AzureADGroup -All $true | Select DisplayName<br\/><br\/><br\/>$ZSourceDomain = &quot;sourcedomain.com&quot;<br\/>$CSourceDomain = &quot;sourcedomain2.com&quot;<br\/>$DestinationDomain = &quot;destinationdomain3.com&quot;<br\/><br\/>foreach($S in $SG){<br\/><br\/>#connect to source tenant , have to save creds if we are working with a lot of groups if not comment out $zpassword and $zpassword\u00a0<br\/>#https:\/\/sid-500.com\/2020\/12\/01\/powershell-connect-to-azure-with-stored-credentials\/<br\/>$zpassword = ConvertTo-SecureString (Unprotect-CmsMessage -Path C:\\Scripts\\pwd.txt) -AsPlainText -Force<br\/>$zcred= New-Object System.Management.Automation.PSCredential (&#039;XXXXXX&#039;, $zpassword)<br\/>Connect-AzureAD -credential $zcred<br\/><br\/><br\/>$List = @()<br\/>$List = Get-AzureADGroup -SearchString &quot;$S&quot;<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\/>#connect to source tenant , have to save creds if we are working with a lot of groups if not comment out $fpassword and $fpassword\u00a0<br\/>#connect to destination tenant Azure AD<br\/>#https:\/\/sid-500.com\/2020\/12\/01\/powershell-connect-to-azure-with-stored-credentials\/<br\/>$fpassword = ConvertTo-SecureString (Unprotect-CmsMessage -Path C:\\Scripts\\fpwd.txt) -AsPlainText -Force<br\/>$fcred= New-Object System.Management.Automation.PSCredential (&#039;XXXXXXX&#039;, $fpassword)<br\/>Connect-AzureAD -credential $fcred<br\/><br\/>New-AzureADGroup -DisplayName $List.DisplayName -MailEnabled $false -SecurityEnabled $true -MailNickName &quot;NotSet&quot;<br\/><br\/>foreach($ZListMemberUPN in $ZListMembersUPN){<br\/><br\/><br\/>add-azureadgroupmember -Identity $List.DisplayName -Member $ZListMemberUPN.replace(&quot;$ZSourceDomain&quot;,&quot;$DestinationDomain&quot;)<br\/><br\/>}<br\/><br\/>foreach($CListMemberUPN in $CListMembersUPN){<br\/><br\/><br\/>add-azureadgroupmember -Identity $List.DisplayName -Member $CListMemberUPN.replace(&quot;$CSourceDomain&quot;,&quot;$DestinationDomain&quot;)<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-SecurityGroups%2Bmembers.ps1\" title=\"See copy-adzuread-SecurityGroups%2Bmembers.ps1\" target=\"_blank\" class=\"code-embed-name\">copy-adzuread-SecurityGroups%2Bmembers.ps1<\/a> <a href=\"https:\/\/raw.github.com\/pariswells\/pariswells.com\/master\/copy-adzuread-SecurityGroups%2Bmembers.ps1\" title=\"Back to copy-adzuread-SecurityGroups%2Bmembers.ps1\" class=\"code-embed-raw\" target=\"_blank\">view raw<\/a> <\/div> <\/div><\/div>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6124","post","type-post","status-publish","format-standard","hentry","category-research"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 4.9.8 - aioseo.com -->\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"paris\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 4.9.8\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Welcome to Pariswells.com |\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Copy Azure AD Security Groups and Membership one Tenancy to Another | Welcome to Pariswells.com\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2022-09-06T11:01:51+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2022-11-23T00:57:18+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Copy Azure AD Security Groups and Membership one Tenancy to Another | Welcome to Pariswells.com\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#article\",\"name\":\"Copy Azure AD Security Groups and Membership one Tenancy to Another | Welcome to Pariswells.com\",\"headline\":\"Copy Azure AD Security Groups and Membership one Tenancy to Another\",\"author\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/author\\\/paris#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/#organization\"},\"datePublished\":\"2022-09-06T11:01:51+00:00\",\"dateModified\":\"2022-11-23T00:57:18+00:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#webpage\"},\"articleSection\":\"Research\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/pariswells.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/category\\\/research#listItem\",\"name\":\"Research\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/category\\\/research#listItem\",\"position\":2,\"name\":\"Research\",\"item\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/category\\\/research\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#listItem\",\"name\":\"Copy Azure AD Security Groups and Membership one Tenancy to Another\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#listItem\",\"position\":3,\"name\":\"Copy Azure AD Security Groups and Membership one Tenancy to Another\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/category\\\/research#listItem\",\"name\":\"Research\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/#organization\",\"name\":\"Welcome to Pariswells.com\",\"url\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/author\\\/paris#author\",\"url\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/author\\\/paris\",\"name\":\"paris\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/93b8ee3f592ac401167f870452bd82d43de80152cd3524e2853403658ada9984?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"paris\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#webpage\",\"url\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another\",\"name\":\"Copy Azure AD Security Groups and Membership one Tenancy to Another | Welcome to Pariswells.com\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/research\\\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/author\\\/paris#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/author\\\/paris#author\"},\"datePublished\":\"2022-09-06T11:01:51+00:00\",\"dateModified\":\"2022-11-23T00:57:18+00:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/\",\"name\":\"Welcome to Pariswells.com\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/pariswells.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Copy Azure AD Security Groups and Membership one Tenancy to Another | Welcome to Pariswells.com","description":"","canonical_url":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#article","name":"Copy Azure AD Security Groups and Membership one Tenancy to Another | Welcome to Pariswells.com","headline":"Copy Azure AD Security Groups and Membership one Tenancy to Another","author":{"@id":"https:\/\/pariswells.com\/blog\/author\/paris#author"},"publisher":{"@id":"https:\/\/pariswells.com\/blog\/#organization"},"datePublished":"2022-09-06T11:01:51+00:00","dateModified":"2022-11-23T00:57:18+00:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#webpage"},"isPartOf":{"@id":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#webpage"},"articleSection":"Research"},{"@type":"BreadcrumbList","@id":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/pariswells.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog\/category\/research#listItem","name":"Research"}},{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog\/category\/research#listItem","position":2,"name":"Research","item":"https:\/\/pariswells.com\/blog\/category\/research","nextItem":{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#listItem","name":"Copy Azure AD Security Groups and Membership one Tenancy to Another"},"previousItem":{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#listItem","position":3,"name":"Copy Azure AD Security Groups and Membership one Tenancy to Another","previousItem":{"@type":"ListItem","@id":"https:\/\/pariswells.com\/blog\/category\/research#listItem","name":"Research"}}]},{"@type":"Organization","@id":"https:\/\/pariswells.com\/blog\/#organization","name":"Welcome to Pariswells.com","url":"https:\/\/pariswells.com\/blog\/"},{"@type":"Person","@id":"https:\/\/pariswells.com\/blog\/author\/paris#author","url":"https:\/\/pariswells.com\/blog\/author\/paris","name":"paris","image":{"@type":"ImageObject","@id":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/93b8ee3f592ac401167f870452bd82d43de80152cd3524e2853403658ada9984?s=96&d=mm&r=g","width":96,"height":96,"caption":"paris"}},{"@type":"WebPage","@id":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#webpage","url":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another","name":"Copy Azure AD Security Groups and Membership one Tenancy to Another | Welcome to Pariswells.com","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/pariswells.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another#breadcrumblist"},"author":{"@id":"https:\/\/pariswells.com\/blog\/author\/paris#author"},"creator":{"@id":"https:\/\/pariswells.com\/blog\/author\/paris#author"},"datePublished":"2022-09-06T11:01:51+00:00","dateModified":"2022-11-23T00:57:18+00:00"},{"@type":"WebSite","@id":"https:\/\/pariswells.com\/blog\/#website","url":"https:\/\/pariswells.com\/blog\/","name":"Welcome to Pariswells.com","inLanguage":"en-US","publisher":{"@id":"https:\/\/pariswells.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Welcome to Pariswells.com |","og:type":"article","og:title":"Copy Azure AD Security Groups and Membership one Tenancy to Another | Welcome to Pariswells.com","og:url":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another","article:published_time":"2022-09-06T11:01:51+00:00","article:modified_time":"2022-11-23T00:57:18+00:00","twitter:card":"summary","twitter:title":"Copy Azure AD Security Groups and Membership one Tenancy to Another | Welcome to Pariswells.com"},"aioseo_meta_data":{"post_id":"6124","title":null,"description":null,"keywords":[],"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":"{\"article\":{\"articleType\":\"BlogPosting\"},\"course\":{\"name\":\"\",\"description\":\"\",\"provider\":\"\"},\"faq\":{\"pages\":[]},\"product\":{\"reviews\":[]},\"recipe\":{\"ingredients\":[],\"instructions\":[],\"keywords\":[]},\"software\":{\"reviews\":[],\"operatingSystems\":[]},\"webPage\":{\"webPageType\":\"WebPage\"},\"blockGraphs\":[]}","pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","location":null,"local_seo":null,"breadcrumb_settings":null,"limit_modified_date":false,"ai":null,"created":"2022-09-06 04:32:24","updated":"2022-11-23 01:11:32","primary_term":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/pariswells.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/pariswells.com\/blog\/category\/research\" title=\"Research\">Research<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tCopy Azure AD Security Groups and Membership one Tenancy to Another\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/pariswells.com\/blog"},{"label":"Research","link":"https:\/\/pariswells.com\/blog\/category\/research"},{"label":"Copy Azure AD Security Groups and Membership one Tenancy to Another","link":"https:\/\/pariswells.com\/blog\/research\/copy-azure-ad-security-groups-and-membership-one-tenancy-to-another"}],"_links":{"self":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/6124","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=6124"}],"version-history":[{"count":4,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/6124\/revisions"}],"predecessor-version":[{"id":6365,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/posts\/6124\/revisions\/6365"}],"wp:attachment":[{"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/media?parent=6124"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/categories?post=6124"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pariswells.com\/blog\/wp-json\/wp\/v2\/tags?post=6124"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}