Forum Discussion

marcin-260's avatar
marcin-260
Copper Contributor
Jan 25, 2024

Calling the SPO Site ID?

Hello there, 

 

I'm trying to find the SPO site ID using PowerShell. I have tried using the following command, but it does not return any results.

 

Get-PnPTenantSite| Where-Object {$_.Url -eq "https://companydomainsharepoint.com/sites/mysite"} | select *id

I have verified that the URL buy adding the _api/site after the site and also matches the one from the SharePoint admin center reports.

 

https://companydomain.sharepoint.com/sites/mysite/_api/site

<d:Id m:type="Edm.Guid">*******-***-***-***-********</d:Id>

Is there another way to get the SPO site ID using PowerShell? I appreciate any help or guidance you can provide.

3 Replies

    • marcin-260's avatar
      marcin-260
      Copper Contributor
      Thanks Nicolas, no results. It's does not contain any 'value' property even when pipping out as a full list.
      Is this template specific? The one I'm looking at is SITEPAGEPUBLISHING#0?


      • ganeshsanap's avatar
        ganeshsanap
        MVP

        marcin-260 I think the site Id you are looking for is not returned using the Get-PnPTenantSite command. I even tried using -Detailed with the PowerShell command like below but it did not return the expected Id:

         

        Get-PnPTenantSite -Detailed

        You can try using Get-PnPSite like: 

        $SiteURL = "https://contoso.sharepoint.com/Sites/mysite"
         
        #Connect to SP site
        Connect-PnPOnline -Url $SiteURL -Interactive
        
        #Get site ID
        $Site = Get-PnPSite -Includes ID
         
        #Print site ID
        Write-host -f Green "Site ID: "$Site.Id

         


        Please click Mark as Best Response & Like if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

Resources