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:

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:
- How to Check if a SharePoint Site Exists using PnP PowerShell?
- Get All Lists and Libraries from SharePoint Online Site using PnP PowerShell
- Enable Custom Script in SharePoint Online Using PnP PowerShell
- Get All SharePoint Online Sites using PnP PowerShell
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.