Yes/No Column PnP PowerShell

Get Hub Site Id using PnP PowerShell in SharePoint Online

Introduction

In the vast landscape of SharePoint Online, hub sites serve as the backbone for organizing and connecting related sites, fostering a cohesive digital workplace environment. The Hub Site ID holds significant importance for various tasks, including programmatically searching within the hub association. Today, we embark on a journey to demystify the process of retrieving the Hub Site ID using PnP PowerShell in SharePoint Online.

Prerequisites

Before we begin, ensure your machine is equipped to run PnP PowerShell commands and has the necessary modules installed. If you’re new to PnP PowerShell, refer to my previous blog post PnP PowerShell: How to get started? – Hemant Kabra for a comprehensive guide on commencing your journey.

Get Hub Site Id using PnP PowerShell

Let’s dive into the core of our task: retrieving the Hub Site ID. We’ll leverage the Get-PnPSite cmdlet from PnP PowerShell to achieve this. Follow along as we break down the process step by step:

# Declare the SharePoint Site Collection URL for which the Hub Site ID is required
$HubSiteURL = "https://yourtenant.sharepoint.com/sites/yoursite"

# Connect to the SharePoint Site
Connect-PnPOnline -Url $HubSiteURL -Interactive

# Retrieve the PnP Site Object including the IsHubSite & HubSiteId properties
$PnPSite = Get-PnPSite -Includes IsHubSite,HubSiteId

# Check if the connected site collection is a Hub Site
if ($PnPSite.IsHubSite) {
    # If the site collection is a hub site, get the Hub Site ID
    $HubSiteId = $PnPSite.HubSiteId
    Write-Host "Hub Site ID: $HubSiteId"
} else {
    Write-Host "Given Site Collection is not a Hub Site!"
}

Conclusion

Congratulations! You’ve successfully uncovered the Hub Site ID using PnP PowerShell in SharePoint Online. Armed with this knowledge, you can delve deeper into managing your SharePoint environment with efficiency and confidence. Stay tuned for more insightful tips and tricks to optimize your SharePoint experience on our blog!

Feel free to share your experiences or ask any questions in the comments section below. Happy SharePointing!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *