Get-MgAllSite and Skip Tokens
Describe the bug
The Get-MgAllSite cmdlet returns a maximum of 600 sites. The cmdlet supports a skiptoken parameter to take a nextlink and return the next page of data, but there's no obvious way of finding the token (which is returned by the underlying Graph API - see debug output below).
In other words, this works:
[array]$GraphSites = Invoke-MgGraphRequest -Uri $Uri -Method Get $Graphsites
Name Value
value {Project Zaja, Office 365 for IT Pros (2026 Edition), Critical Project Planning - HR Advice, Critical Project Planning - Legal advice…} @odata.nextLink https://graph.microsoft.com/v1.0/sites/getAllSites?$skiptoken=UGFnZWQ9VFJVRSZwX1RpbWVEZWxldGVkPSZwX0lEPTUyMw @odata.context https://graph.microsoft.com/v1.0/$metadata#sites
This doesn't:
[array]$Sites = Get-MgAllSite $Sites | Select-Object -First 5
DisplayName Id Name
Project Zaja redmondassociates.sharepoint.com,9ba323bf-cf4d-4d8b-a9dc-880cc2341977,971e2d7f-def2-4f61-ba98-50cd95795b13 Project Zaja Office 365 for IT Pros (2026 Edition) redmondassociates.sharepoint.com,113046d4-4c00-4a8f-a0b0-9ce5a363cf9a,70e4385d-48f9-4d5e-95a0-f5e890978ac5 Office 365 for IT Pros (2026… Critical Project Planning - HR Advice redmondassociates.sharepoint.com,8094d05f-eece-477a-a700-34a5d210b307,a9415985-41f2-4af4-a403-57fca1597f63 Critical Project Planning - … Critical Project Planning - Legal advice redmondassociates.sharepoint.com,2d67176d-eb90-4d87-b51e-56b0b389e6e9,a9415985-41f2-4af4-a403-57fca1597f63 Critical Project Planning - … MDO License Assignments redmondassociates.sharepoint.com,da416236-22fe-48af-960d-252b30e0d9d7,c2730fcf-4fbd-48b4-a127-b6c664222c21 MDO License Assignments
The cmdlet should support an All parameter to allow all sites to be retrieved.
Expected behavior
I expect a nextlink token to be available if Get-MgAllSites finds more than 600 sites.
How to reproduce
See above.
SDK Version
V2.30
Latest version known to work for scenario above?
No response
Known Workarounds
Use the Graph API
Debug output
Headers: Cache-Control : no-store, no-cache Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : b017fe39-b336-45f2-8833-1638c8661947 client-request-id : 25dfb918-0a3a-44f1-bbc5-b23aff14bbba x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"North Europe","Slice":"E","Ring":"4","ScaleUnit":"008","RoleInstance":"DU2PEPF00045843"}} splogid : da81c8a1-409e-a000-0bf7-a1ac56684946 odata-version : 4.0 Date : Tue, 23 Sep 2025 09:39:00 GMT
Body:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites",
"@odata.nextLink": "https://graph.microsoft.com/v1.0/sites/microsoft.graph.getAllSites()?$skiptoken=UGFnZWQ9VFJVRSZwX1RpbWVEZWxldGVkPSZwX0lEPTUyMw",
"value": [
{
"createdDateTime": "2025-09-23T09:24:29Z",
"id": "redmondassociates.sharepoint.com,9ba323bf-cf4d-4d8b-a9dc-880cc2341977,971e2d7f-def2-4f61-ba98-50cd95795b13",
"name": "Project Zaja",
"webUrl": "https://redmondassociates.sharepoint.com/sites/ProjectZaja",
"displayName": "Project Zaja",
"isPersonalSite": false,
"siteCollection": {
"hostname": "redmondassociates.sharepoint.com"
},
"root": {}Click to expand log
<Log output here>
Configuration
$psversiontable
Name Value
PSVersion 7.5.3 PSEdition Core GitCommitId 7.5.3 OS Microsoft Windows 10.0.26100 Platform Win32NT PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…} PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 WSManStackVersion 3.0
Other information
No response
It seems like Get-MgAllSite retrieves more than 600 sites at a time. I had forgotten that sites take some time to be visible via the Graph after creation. However, this doesn't take away from the problem (which might now be a documentation issue). If the cmdlet fetches all sites automatically, then the documentation should say so and remove the Skip parameter. If it doesn't, then the documentation should explain how to fetch all sites using Get-MgAllSite. In both cases, supporting the All parameter would be a good idea because it's consistent with what Get-MgSite and other similar cmdlets do.
This Cmdlet isn't being treated as a collection response so it's not getting standard collection response semantics applied.
It might be due to the autorest directive for the Sites module