-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #702 from reshmee011/getsiteid_MsGraph
new sample script to get site id from Microsoft Graph
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
55
scripts/spo-get-siteid-from-microsoftgraph/assets/sample.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} | ||
] |