2

I am currently working with some code that gives me the following:

  • Site Collection Guid

I would like to fetch the site url using the site collection Guid with PNP PowerShell.

Does anyone have any idea how to do this?

1
  • 1
    what is the exact issue? Do you want to retrieve the GUID of site collection using site URL or retrieve URL of Site collection using GUID? Commented May 14, 2019 at 10:05

2 Answers 2

2

The Microsoft Graph can provide you the information about the site collection. See the paragraph Note for existing SharePoint developers and especially the last example.

The endpoint URL for your use case would then be

  • https://graph.microsoft.com/v1.0/sites/{hostname},{spsite-id}

Resulting URL for tenant mytenant.sharepoint.com and site collection 21e6689e-ddd0-48eb-1234-0357c5fa1093:

  • https://graph.microsoft.com/v1.0/sites/mytenant.sharepoint.com,21e6689e-ddd0-48eb-1234-0357c5fa1093

The response then looks like this:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites/$entity",
    "createdDateTime": "2018-01-12T21:27:53.963Z",
    "description": "",
    "id": "mytenant.sharepoint.com,21e6689e-ddd0-48eb-1234-0357c5fa1093,2cb44c34-5aee-4c5e-1234-9a2d36b8204b",
    "lastModifiedDateTime": "2019-04-02T10:58:01Z",
    "name": "mysitecollection",
    "webUrl": "https://mytenant.sharepoint.com/sites/mysitecollection",
    "displayName": "My Site Collection",
    "root": {},
    "siteCollection": {
        "hostname": "mytenant.sharepoint.com"
    }
}
0

Edit - Below will work only for SP on premises environment.

I think you can use Pure Powershell command.

Get-SPSite -Identity "121321-12312-12312-1231231"

Identity parameter takes url or GUID, below is text from microsoft documentation

-Identity Specifies the URL or GUID of the site collection to get. The type must be a valid URL, in the form, https://server_name or https://server_name/sites/sitename, or a valid GUID (for example, 12345678-90ab-cdef-1234-567890bcdefgh).

https://docs.microsoft.com/en-us/powershell/module/sharepoint-server/get-spsite?view=sharepoint-ps

Hope this helps...Happy Coding..!!!

2
  • 1
    This will only work when executed in a PowerShell on an OnPremise SharePoint Server, but not in SharePoint Online.
    – Anon
    Commented May 14, 2019 at 12:39
  • @Anon.... true... my bad... I just checked PnP documentation, it does not accept GUID. Commented May 14, 2019 at 12:46

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.