Skip to content

Commit

Permalink
Merge pull request #702 from reshmee011/getsiteid_MsGraph
Browse files Browse the repository at this point in the history
new sample script to get site id from Microsoft Graph
  • Loading branch information
pkbullock authored Jun 18, 2024
2 parents 6835dda + 3ffd90c commit cafc6cc
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
53 changes: 53 additions & 0 deletions scripts/spo-get-siteid-from-microsoftgraph/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
plugin: add-to-gallery
---

# Retrieves site id from Microsoft Graph

## Summary

Retrieves a SiteId from Microsoft Graph using PnP PowerShell. This can be particularly useful when making further API calls that require the SiteId.

![Example Screenshot](assets/preview.png)

### Prerequisites

- The user account that runs the script must have access to the SharePoint Online site.

# [PnP PowerShell](#tab/pnpps)

```powershell
$siteurl = "https://contoso.sharepoint.com/sites/Company311"
Connect-PnPOnline -url $siteurl -interactive
# Extract the domain and site name
$uri = New-Object System.Uri($siteurl)
$domain = $uri.Host
$siteName = $uri.AbsolutePath
# Construct the new URL
$RestMethodUrl = "v1.0/sites/$($domain):$siteName?$select=id"
$site = (Invoke-PnPGraphMethod -Url $RestMethodUrl -Method Get -ConsistencyLevelEventual)
$siteId = $site.id
write-host $siteId
```

[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]

***

## Source Credit

Sample first appeared on [Retrieving SiteId from Microsoft Graph for Subsequent API Calls](https://reshmeeauckloo.com/posts/powershell_getsiteid_graph/)

## Contributors

| Author(s) |
|-----------|
| [Reshmee Auckloo](https://github.com/reshmee011) |


[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)]
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-get-siteid-from-microsoftgraph" aria-hidden="true" />
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions scripts/spo-get-siteid-from-microsoftgraph/assets/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
[
{
"name": "spo-get-siteid-from-microsoftgraph",
"source": "pnp",
"title": "Retrieves site id from Microsoft Graph",
"shortDescription": "Retrieves a SiteId from Microsoft Graph using PnP PowerShell. This can be particularly useful when making further API calls that require the SiteId.",
"url": "https://pnp.github.io/script-samples/spo-get-siteid-from-microsoftgraph/README.html",
"longDescription": [
"Retrieves SiteId from Microsoft Graph using PnP PowerShell. This can be particularly useful when making further API calls that require the SiteId."
],
"creationDateTime": "2024-06-15",
"updateDateTime": "2024-06-15",
"products": [
"SharePoint",
"SiteId"
],
"metadata": [
{
"key": "PNP-POWERSHELL",
"value": "2.4.0"
}
],
"categories": [
"Report"
],
"tags": [
"modern",
"Connect-PnPOnline",
"Invoke-PnPGraphMethod"
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-get-siteid-from-microsoftgraph/assets/preview.png",
"alt": ""
}
],
"authors": [
{
"gitHubAccount": "reshmee011",
"company": "",
"pictureUrl": "https://avatars.githubusercontent.com/u/7693852?v=4",
"name": "Reshmee Auckloo"
}
],
"references": [
{
"name": "Want to learn more about PnP PowerShell and the cmdlets",
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.",
"url": "https://aka.ms/pnp/powershell"
}
]
}
]

0 comments on commit cafc6cc

Please sign in to comment.