How to Get SharePoint Site ID using PnP PowerShell?

Recently, I was working with a PowerShell script that wanted to get the SharePoint site ID. I used PnP PowerShell for this. In this tutorial, I will show you how to get the SharePoint site ID using PnP PowerShell.

Get SharePoint Site ID Using PnP PowerShell

To get the SharePoint site ID using PnP PowerShell, write the PnP PowerShell script below.

# Define the site collection URL
$siteUrl = "https://szg52.sharepoint.com/sites/PowerShellFAQs"

# Connect to SharePoint Online
Connect-PnPOnline -Url $siteUrl -Interactive

$site = Get-PnPSite -Includes ID
Write-host "Site ID: " $site.Id 

After I executed the above script, it displayed the SharePoint Online site ID. You can see it in the screenshot below:

Get SharePoint Site ID Using PnP PowerShell

Read Change a SharePoint Site URL Using PnP PowerShell

Get SharePoint Online Site ID using SharePoint Online Management Shell

If you prefer to use the SharePoint Online management shell, you can also get the SharePoint site ID.

If you prefer, you can also use the SharePoint Online Management Shell to retrieve the Site ID. This method involves using the Get-SPOSite cmdlet:

Connect-SPOService -Url "https://szg52-admin.sharepoint.com"
$site = Get-SPOSite -Identity "https://szg52.sharepoint.com/sites/PowerShellFAQs"
$siteId = $site.Id
Write-Output "The Site ID is: $siteId"

This script connects to the SharePoint Online Admin Center and retrieves the Site ID for the specified site.

Conclusion

In this tutorial, I have explained how to use PnP PowerShell to get the SharePoint Online site ID. I have also explained how to use the SharePoint Online management shell to get the SharePoint Online site ID.

You may like the following tutorials:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.