Iterate through all Sites using PowerShell
-
24-01-2021 - |
Question
I am trying to disassociate all of my sites with my hub site and then associate them all again so that I can force an update of the styling. I know the code to remove an association and then create an association however I haven't been able to find any code to iterate through each site. There are no sub-sites and each site is found on https://.sharepoint.com/sites/ .
Thanks :)
Solution
We can download the SharePoint Online Management Shell.
And connect SharePoint online admin site and get the hub sites using the PowerShell below.
connect-SPOService -Url https://xxx-admin.sharepoint.com
Get-SPOHubSite
And get all the sites associated hub site base on the sub site Id.
$hubSiteId="9067810e-81f3-4798-a7b6-9d0b5daf25ce"
$sites = Get-SPOSite -Limit ALL
foreach ($site in $sites) {
$siteDetailed = Get-SPOSite -Detailed $site.Url
if($siteDetailed.HubSiteId -eq $hubSiteId){
$site.Url
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange