{"id":6428,"date":"2021-03-03T14:30:17","date_gmt":"2021-03-03T14:30:17","guid":{"rendered":"https:\/\/www.softreetechnology.com\/?p=6428"},"modified":"2021-03-03T14:30:17","modified_gmt":"2021-03-03T14:30:17","slug":"get-set-and-remove-associated-site-using-powershell","status":"publish","type":"post","link":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/","title":{"rendered":"Get, Set and Remove Associated site using PowerShell"},"content":{"rendered":"<p>[vc_row][vc_column][vc_column_text]In this blog, we are going to discuss about how to create Hub site, associate a site to it, get the associated site and remove the associated site using PowerShell.<\/p>\n<p>&nbsp;<\/p>\n<p>What is Hub Site:<\/p>\n<p>Hub sites brings the related sites together to roll up news, events &amp; to simplify search with shared navigation across the sites. These sites are meant to fulfil all the organisational need depending upon the projects and departments etc. A hub site can have team sites and communication sites associated to it. You can easily set related sites with shared look, shared global navigation, search and news.<\/p>\n<p>Follow the below steps to perform hub site operations using PnP PowerShell.<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>Register a site as Hub.<\/li>\n<li>Associate a site to Hub Site.<\/li>\n<li>Get Associated Site of Hub site<\/li>\n<li>Remove Associated site<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>Register a site as Hub: &#8211;<\/p>\n<p>Follow the below code to register a site as hub<\/p>\n<p>&nbsp;<\/p>\n<p>$siteURL = Read-Host \u201cEnter the site Url\u201d<\/p>\n<p>&nbsp;<\/p>\n<p>#Enter user name and password<\/p>\n<p>$credential = Get-Credential<\/p>\n<p>&nbsp;<\/p>\n<p>#connect pnp online<\/p>\n<p>Connect-PnPOnline -Url $siteURl -Credentials $credential<\/p>\n<p>&nbsp;<\/p>\n<p>#register associate site to hub site<\/p>\n<p>Register-PnPHubSite -Site $siteURL<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>In the parameter of \u201csiteURL\u201d, Enter that site URL which you want to register as Hub.<\/p>\n<p>A Credential pop up will open as shown below. Enter your SharePoint username and password.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-6429 size-full\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2021\/03\/1.png\" alt=\"\" width=\"382\" height=\"324\" \/><\/p>\n<p>Before running the script: &#8211;<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-6438 size-full\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2021\/03\/2-1.png\" alt=\"\" width=\"934\" height=\"370\" \/><\/p>\n<p>After running the script: &#8211;<\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-6437 size-full\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2021\/03\/3-1.png\" alt=\"\" width=\"836\" height=\"351\" \/><\/p>\n<p>Associate a site to Hub Site: &#8211;<\/p>\n<p>Follow the below powershell code to associate a site to hubsite.<\/p>\n<p>&nbsp;<\/p>\n<p>$tenantURL = Read-Host \u201cEnter Tenant url\u201d<\/p>\n<p>$hubURL = Read-Host \u201cEnter Hubsite Url\u201d<\/p>\n<p>$siteURL = Read-Host \u201cPlease provide site Url\u201d<\/p>\n<p>&nbsp;<\/p>\n<p>#enter the user name and password<\/p>\n<p>$credential = Get-Credential<\/p>\n<p>&nbsp;<\/p>\n<p>#connect-Pnp Online<\/p>\n<p>Connect-PnPOnline -Url $tenantURL -Credentials $credential<\/p>\n<p>&nbsp;<\/p>\n<p>#add associated site to a hubsite<\/p>\n<p>Add-PnPHubSiteAssociation -Site $siteURL -HubSite $hubURL<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>In the parameter of \u201ctenantURl\u201d,enter your admin url like <a href=\"https:\/\/cottoso-admin.sharepoint.com\">https:\/\/cottoso-admin.sharepoint.com<\/a>.<\/p>\n<p>In \u201chubURL\u201d parameter, enter your hub site url in which you want to associate a site.<\/p>\n<p>&nbsp;<\/p>\n<p>In \u201csiteURL\u201d, provide the site url that you want to associate to hub site.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Before running the script: &#8211;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-6432 size-full\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2021\/03\/4.png\" alt=\"\" width=\"746\" height=\"349\" \/><\/p>\n<p>After running the script: &#8211;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-6433 size-full\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2021\/03\/5.png\" alt=\"\" width=\"710\" height=\"372\" \/><\/p>\n<p>Get Associated Site: &#8211;<\/p>\n<p>&nbsp;<\/p>\n<p>Follow the below powershell code to get all associated site from a hub site and print it.<\/p>\n<p>&nbsp;<\/p>\n<p>$hubURL = Read-Host \u201cEnter hubsite Url\u201d<\/p>\n<p>&nbsp;<\/p>\n<p>#enter the user name and password<\/p>\n<p>$credential = Get-Credential<\/p>\n<p>&nbsp;<\/p>\n<p>#Connect Pnp Online<\/p>\n<p>Connect-PnPOnline -Url $hubURL -Credentials $credential<\/p>\n<p>&nbsp;<\/p>\n<p>#get associated site<\/p>\n<p>$siteColl = Get-PnPHubSiteChild -Identity $hubURL<\/p>\n<p>&nbsp;<\/p>\n<p>foreach($site in $siteColl){<\/p>\n<p>#print the sites<\/p>\n<p>Write-Host $site<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>In the parameter of \u201chubURL\u201d,enter your hub site url from which you want to get all the associate site.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>You can see your associated site url in the console as shown in below screenshot.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-6434 size-full\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2021\/03\/6.png\" alt=\"\" width=\"1335\" height=\"249\" \/><\/p>\n<p>Remove Associated site: &#8211;<\/p>\n<p>Follow the below powershell code to remove associated site<\/p>\n<p>&nbsp;<\/p>\n<p>$tenantURL = Read-Host \u201cprovide tenant url\u201d<\/p>\n<p>$siteURL = Read-Host \u201cprovide site url\u201d<\/p>\n<p>&nbsp;<\/p>\n<p>#enter the username and password<\/p>\n<p>$credential = Get-Credential<\/p>\n<p>&nbsp;<\/p>\n<p>#Connect PnP Online<\/p>\n<p>Connect-PnPOnline -Url $tenantURL -Credentials $credential<\/p>\n<p>&nbsp;<\/p>\n<p>#remove Hub associated site<\/p>\n<p>Remove-PnPHubSiteAssociation -Site $siteURL<\/p>\n<p>&nbsp;<\/p>\n<p>In the parameter of \u201ctenantURl\u201d,enter your admin url like <a href=\"https:\/\/cottoso-admin.sharepoint.com\">https:\/\/cottoso-admin.sharepoint.com<\/a><\/p>\n<p>In \u201csiteURL\u201d, provide the site url that you want to remove from association to hub site.<\/p>\n<p>&nbsp;<\/p>\n<p>Before running the script: &#8211;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-6435 size-full\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2021\/03\/7.png\" alt=\"\" width=\"710\" height=\"372\" \/><\/p>\n<p>After running the script: &#8211;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-6436 size-full\" src=\"https:\/\/www.softreetechnology.com\/wp-content\/uploads\/2021\/03\/8.png\" alt=\"\" width=\"746\" height=\"349\" \/><\/p>\n<blockquote><p><strong>Conclusion: &#8211;<\/strong>\u00a0\u00a0 After running the above piece of code I hope it takes less time in comparison to the manual procedure. Hence using the PowerShell script to create hub site, associate a site to it, get the associated site and remove the associated site is more effective procedure.<\/p><\/blockquote>\n<p>[\/vc_column_text][\/vc_column][\/vc_row]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[vc_row][vc_column][vc_column_text]In this blog, we are going to discuss about how to create Hub site, associate a site to it, get the associated site and remove the associated site using PowerShell. &nbsp; What is Hub Site: Hub sites brings the related sites together to roll up news, events &amp; to simplify search with shared navigation across the sites. These sites are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6439,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[],"class_list":["post-6428","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-sharepoint"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Get, Set and Remove Associated site using PowerShell - Softree Technology<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get, Set and Remove Associated site using PowerShell - Softree Technology\" \/>\n<meta property=\"og:description\" content=\"[vc_row][vc_column][vc_column_text]In this blog, we are going to discuss about how to create Hub site, associate a site to it, get the associated site and remove the associated site using PowerShell. &nbsp; What is Hub Site: Hub sites brings the related sites together to roll up news, events &amp; to simplify search with shared navigation across the sites. These sites are [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"Softree Technology\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-03T14:30:17+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get, Set and Remove Associated site using PowerShell - Softree Technology","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Get, Set and Remove Associated site using PowerShell - Softree Technology","og_description":"[vc_row][vc_column][vc_column_text]In this blog, we are going to discuss about how to create Hub site, associate a site to it, get the associated site and remove the associated site using PowerShell. &nbsp; What is Hub Site: Hub sites brings the related sites together to roll up news, events &amp; to simplify search with shared navigation across the sites. These sites are [&hellip;]","og_url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/","og_site_name":"Softree Technology","article_published_time":"2021-03-03T14:30:17+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"Written by":"admin","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/#article","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/"},"author":{"name":"admin","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b"},"headline":"Get, Set and Remove Associated site using PowerShell","datePublished":"2021-03-03T14:30:17+00:00","mainEntityOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/"},"wordCount":617,"commentCount":0,"publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/#primaryimage"},"thumbnailUrl":"","articleSection":["SharePoint"],"inLanguage":"en","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/","url":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/","name":"Get, Set and Remove Associated site using PowerShell - Softree Technology","isPartOf":{"@id":"https:\/\/softreetechnology.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/#primaryimage"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/#primaryimage"},"thumbnailUrl":"","datePublished":"2021-03-03T14:30:17+00:00","breadcrumb":{"@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/#primaryimage","url":"","contentUrl":""},{"@type":"BreadcrumbList","@id":"https:\/\/softreetechnology.com\/blog\/sharepoint\/get-set-and-remove-associated-site-using-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/softreetechnology.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Get, Set and Remove Associated site using PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/softreetechnology.com\/blog\/#website","url":"https:\/\/softreetechnology.com\/blog\/","name":"Softree Technology","description":"Celebrating 10+ Years in SharePoint Consulting !","publisher":{"@id":"https:\/\/softreetechnology.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/softreetechnology.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/softreetechnology.com\/blog\/#organization","name":"Softree Technology","url":"https:\/\/softreetechnology.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","contentUrl":"https:\/\/softreetechnology.com\/blog\/wp-content\/uploads\/2023\/03\/cropped-white-logo-soft.png","width":844,"height":230,"caption":"Softree Technology"},"image":{"@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/98740297642f06debccdcee2de84086b","name":"admin","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/softreetechnology.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/6fc78c8a7aa3fb0bf43c3b9a2e3962d7?s=96&d=mm&r=g","caption":"admin"},"sameAs":["https:\/\/softreeconsulting.com"],"url":"https:\/\/softreetechnology.com\/blog\/author\/admin\/"}]}},"_links":{"self":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6428","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/comments?post=6428"}],"version-history":[{"count":0,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/posts\/6428\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/media?parent=6428"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/categories?post=6428"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/softreetechnology.com\/blog\/wp-json\/wp\/v2\/tags?post=6428"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}