Please provide me the solution for below requirements:

  1. How to get "Site Url" for any SharePoint Online Site if I have the "Site Id"

  2. How to get "Site Id" for any SharePoint Online Site if I have the "Site Url"

When I am using below command, this not showing any Site Id/Id property which we generally get if we use Get-SPSite cmd for On-Prem Sites.

Get-SPOSite -identity <SiteUrl> | select *     
Get-SPOSite <SiteUrl> -Detailed

3 Answers 3


There is no exposed ID property on the site object in PowerShell. For all intents and purposes, the Url is the "site id". In all commands where you would need to supply something like an ID, you pass in the site URL.

In order to do it in PowerShell, you will need to install the SharePoint Online client components and use CSOM to get the site guid.

$context = New-Object Microsoft.SharePoint.Client.ClientContext("https://tenant.sharepoint.com/teams/eric")
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($credential.UserName,$credential.Password)
$site = $context.Site

Note that there is no way to construct a context object via the guid. Check out the constructor information. It is either a Uri or a string of the absolute Url.

So realistically, forget about the notion of a Site Id and think in terms of Urls as your unique identifier.

  • Hi Eric, Thank you so much for the response. I am good with your answer for my question (#2). For question #1, I require your valuable input. I am having a report(csv format), where I have the SiteId (GUID) for SharePointOnline site, now I have to get the Site Url using this Site Id, using CSOM Or PowerShell. Also this Get-SPOSite does not accept the "Site Id" Aug 30, 2016 at 16:53
  • AFAIK you can't, there is no constructor available that will take a guid as an input to establish a context. So to my knowledge, #1 is not possible. Aug 30, 2016 at 17:04

There is a slow method how to get site collection url by guid: enumerate site collections in the tenant, load id for each inside the loop and compare it with the guid you have.

Another method is to use Search API: perform search with Path:{url} and then get SiteID managed property.


Do it with PnP:

$SiteName = 'MySite'
$SiteURL = "https://$TenantURL/sites/$SiteName"
$UserName='[email protected]'
$Password = 'MyPa$$word'
$SecurePassword = ConvertTo-SecureString $Password -AsPlainText -Force
$Cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $UserName, $SecurePassword
Connect-PnPOnline -Url $SiteURL -Credentials $Cred
$Site = Get-PnPSite -Includes ID
Write-host -f Green "Site Collection ID:"$Site.Id

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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