2

I need to make a list of all the sites that are under a HUB. So I'm wondering if there is a way to see a list of all the sites that are part of a certain HUB, this to better manage them.

3
  • You want only list in csv or webpart ? Dec 5 '19 at 17:14
  • Check the PowerShell code given here in question if this helps you. Dec 5 '19 at 18:47
  • @SiddharthVaghasia it doesn't matter as long as I can see the sites, at least their urls Dec 6 '19 at 20:31
3

This can be achieved thru SharePoint online admin center URL as well as PnP PowerShell script.

Approach 1:

Step 1:

Go to the https://tenant-admin.sharepoint.com url Click Active sites link from left side panel then we can see all active sites report in the dashboard.

Step 2:

Then from the “Active sites” dashboard click on “Hub” -> Filter by Hub -> then select your hub site – this will list down all sites those are connected to that particular hub site.

We will get the below screen:

enter image description here

Now – we can see all sites those are connected to the hub site “SP Hub Site”

enter image description here

Approach 2: by exporting the sites report to csv

From the “Active sites” dashboard click on “Export” button. This will export all sharepoint online sites in csv file to your local download folder. enter image description here

We will get the active sites report as below – from there we can filter as per our need. enter image description here

Approach 3: Using PnP PowerShell

Script 1: Get all associated sites for a particular hub site

CLS
$userName = "Global-sharepoint2019@globalsharepoint2019.onmicrosoft.com"
$passWord = "YourPassWord"
$encPassWord = convertto-securestring -String $passWord -AsPlainText -Force
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist $userName, $encPassWord

Connect-PnPOnline -Url "https://globalsharepoint2019-admin.sharepoint.com/" -Credentials $cred

#Getting the hub site id for which we want to generate the report - those are connected to this hub site.
$hubSiteURL="https://globalsharepoint2019.sharepoint.com/sites/SPHubSite"
$hubSite = Get-PnPTenantSite $hubSiteURL  
$hubSiteId = $hubSite.HubSiteId
write-host " #####Generating sites connected a single hub site report######: " -BackgroundColor DarkGreen
write-host "Hub Site URL: " $hubSiteURL


$associatedSites = @()


#Get all sites associated to the hub site(in the above hub site)
$sitesTenant = Get-PnPTenantSite -Detailed 
$sitesTenant | select url | % {$oneSite = Get-PnPTenantSite $_.url 

  if($oneSite.hubsiteid -eq $hubSiteId)
  {

    write-host "Associated Site URL: " $oneSite.url

     $assocatedSiteObject = New-Object PSObject     
     $assocatedSiteObject | Add-Member -MemberType NoteProperty -name "Hub Site URL" -value $hubSiteURL
     $assocatedSiteObject | Add-Member -MemberType NoteProperty -name "Hub Site ID" -value $hubSiteId
     $assocatedSiteObject | Add-Member -MemberType NoteProperty -Name "Associated Site URL" -value $oneSite.Url
     $assocatedSiteObject | Add-Member -MemberType NoteProperty -name "Associated Site Status" -value $oneSite.Status


     #Add the object with property to an Array
     $associatedSites += $assocatedSiteObject

  }
}

#Export the site array collection to a CSV file
$associatedSites | Export-CSV "C:\Temp\GetAllSitesAssociatedInHubSites\SitesConnectedToSingleHubSiteReprot.csv" -NoTypeInformation  
write-host " #####Generating sites connected a single hub site report- ends here######: " -BackgroundColor DarkYellow

Script 2: Master Report: Get all associated sites for all hub sites from SharePoint online tenant

######The below script will list down all hub sites and their associated connected sites in the tenant.##################
write-host "------------------------------------------------------------------------------------------------------"

write-host " #####Generating master hub sites along with connected sites report for the tenant. ######:" -BackgroundColor DarkGreen

$hubSites=Get-PnPHubSite
$associatedSites = @()
foreach($oneHubSite in $hubSites)
{

   $test=$oneHubSite;
   write-host "Hub Site URL: " $oneHubSite.SiteUrl

   $hubSite = Get-PnPTenantSite $oneHubSite.SiteUrl;  
   $hubSiteId = $hubSite.HubSiteId  

#Get all sites associated to the hub site(in the above hub site)
$sitesTenant = Get-PnPTenantSite -Detailed 
$sitesTenant | select url | % {$oneSite = Get-PnPTenantSite $_.url 

  if($oneSite.hubsiteid -eq $hubSiteId)
  {
    write-host "Associated Site URL: " $oneSite.url
    $assocatedSiteObject = New-Object PSObject

     $assocatedSiteObject | Add-Member -MemberType NoteProperty -name "Hub Site URL" -value $oneHubSite.SiteUrl
     $assocatedSiteObject | Add-Member -MemberType NoteProperty -name "Hub Site ID" -value $oneHubSite.ID
     $assocatedSiteObject | Add-Member -MemberType NoteProperty -Name "Associated Site URL" -value $oneSite.Url
     $assocatedSiteObject | Add-Member -MemberType NoteProperty -name "Associated Site Status" -value $oneSite.Status


     #Add the object with property to an Array
     $associatedSites += $assocatedSiteObject

  }
}

}
#Export the site array collection to a CSV file
$associatedSites | Export-CSV "C:\Temp\GetAllSitesAssociatedInHubSites\SitesConnectedToHubSiteReprotForTenant.csv" -NoTypeInformation  
write-host "##### Generating master hub sites along with connected sites report for the tenant ends here ######:" -BackgroundColor DarkYellow

######The below script will list down all hub sites and their associated connected sites in the tenant - ends here##################

Script execution example: enter image description here

Exported Hub and associated sites report .csv example: enter image description here

Reference URL:

https://global-sharepoint.com/powershell/office-365-retrieve-hub-sites-and-associated-sites-using-pnp-powershell/

0

You can use PnP PowerShell to get the list of associated sites of a hub site.

Open SharePoint Online Management Shell, then run the command below to install PnP module:

Install-Module SharePointPnPPowerShellOnline

Then paste and change the URLs of SharePoint admin center and hub site in the command below, then run it in SharePoint Online management shell:

Connect-PnPOnline -Url https://tenant-admin.sharepoint.com

# get the hub site id
$hubSite = Get-PnPTenantSite "https://tenant.sharepoint.com/sites/sitename"
$hubSiteId = $hubSite.HubSiteId

# get all sites associated to the hub
$sites = Get-PnPTenantSite -Detailed
$sites | select url | % { 
  $s = Get-PnPTenantSite $_.url 
  if($s.hubsiteid -eq $hubSiteId){
    write-host $s.url
  }
}
2
  • I'm very unfamiliar with PowerShell, how exactly can I run this code? Dec 6 '19 at 20:32
  • I update my reply, you can check it. Dec 9 '19 at 8:44
0

You can achieve it using the SharePoint Online PowerShell or PNP powershell. Their is limitation of PowerShell commands so i have to write the below code, it will take time as per your tenant's number of site collection.

To run the below script you need SharePoint Tenant Admin rights.

Using SPO PowerShell:

#connect to Tenant admin 
Connect-SPOService https://YOURTENANTNAME-admin.sharepoint.com

#get all hubsites in the Tenant
$sites = Get-SPOSite -Limit All 

#get all sites in tenant using the SPOPowershell
$hubsites = Get-SPOHubSite

#output array
$HubSiteassociate = @()

#file location where CSV will be stored
$fileLocation = "C:\temp\testscript\HubSiteAssociationReport.csv"

#iterating throw all HubSites
foreach($h in $hubsites)
{    
    $hubid = $h.SiteId

    #iterating throw all Sites collection
    foreach($site in $sites)   
    {
        #pulling the information for indviual site collection
        $sit = Get-SPOSite $site.url               

        #checking if the Hubsite ID match with Site collection's HubSite id
        if($hubid -eq $sit.HubSiteId)
        {

            $HubSite = New-Object PSObject
            $HubSite | Add-Member -MemberType NoteProperty -name "HUbSite Name" -value $h.Title
            $HubSite | Add-Member -MemberType NoteProperty -Name "Hub Site URL" -value $h.SiteUrl
            $HubSite | Add-Member -MemberType NoteProperty -Name "Assoicated Site Url" -value $sit.url
            $HubSite | Add-Member -MemberType NoteProperty -Name "is it Root Hub Site" -value $sit.IsHubSite

            $HubSiteassociate += $hubsite
        }
    }
}

#output the restults
$HubSiteassociate | Export-Csv $fileLocation -NoTypeInformation

#disposing
Disconnect-SPOService

Read the complete post here: Office 365: Get List of All Hub Sites along with associated Sites collection in a Tenant

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.