microsoftgraph / microsoftgraph/msgraph-sdk-powershell

Get-MgAllSite Doesn't Respect the Top Parameter

Open
#3,405 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Service issue Status: Needs Investigation type:bug
Dominant language
C#
Stars
898
Forks
230
Avg merge
2d 5h
Merged PRs (30d)
31

Description

Describe the bug

I am trying to find the first site with a display name starting with A. The cmdlet ignores the Top parameter (it's also incredibly slow - debug implies that multiple HTTP requests are made to retrieve the sites) and returns all sites with a displayname starting with A.

[array]$Sites = Get-MgAllSite -filter "startsWith(displayName,'A')" -top 1
$Sites.displayName

Azure Automation Runbook Fans
Alain Charnier
Andy's Christmas Party
ALL-IN-1 MAIL
ALL-IN-1 for DOS
Atlanta Restaurants
Ann Conroy (GM Datacenters)
All R &A Users-Everyone is Welcome
Audi e-tron Drivers - Secret Car Plans
All Tenant Member User Accounts
Andrew's Maintenance Planners (Teamwith a

Expected behavior

The expected behavior is that the cmdlet should comply with the Top parameter and return the number of sites specified in the parameter.

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 request.

Debug output

Status Code:
OK

Headers:
Cache-Control : no-store, no-cache
Vary : Accept-Encoding
Strict-Transport-Security : max-age=31536000
request-id : 4492f3cc-5c24-4167-8b87-e06724efd3ab
client-request-id : a936e6e8-ed31-42f3-9bc3-81bdedfec988
x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"North Europe","Slice":"E","Ring":"4","ScaleUnit":"002","RoleInstance":"DU2PEPF0004582C"}}
splogid : 7c82c8a1-9074-a000-4211-67c9056cbfb7
odata-version : 4.0
Date : Tue, 23 Sep 2025 09:50:03 GMT

Body:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites",
"@odata.nextLink": "https://graph.microsoft.com/v1.0/sites/microsoft.graph.getAllSites()?$top=1&$filter=startsWith(displayName%2c%27A%27)&$skiptoken=UGFnZWQ9VFJVRSZwX1RpbWVEZWxldGVkPSZwX0lEPTcwNQ",
"value": [
{
"createdDateTime": "2025-01-22T11:19:37Z",
"id": "redmondassociates.sharepoint.com,7b8c30d5-81a2-4582-bd15-d20e5c3091f5,4f47b8eb-8301-4678-b567-e29204a42441",
"name": "Azure Automation Runbook Fans",
"webUrl": "https://redmondassociates.sharepoint.com/sites/Azure.Automation.Fans",
"displayName": "Azure Automation Runbook Fans",
"isPersonalSite": false,
"siteCollection": {
"hostname": "redmondassociates.sharepoint.com"
},
"root": {}
}
]
}

Click to expand log


<Log output here>

Configuration

No response

Other information

$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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Get-MgAllSite cmdlet and compare its -Top handling with the Graph response, which includes $top=1 and an @odata.nextLink. Reproduce the supplied filter and verify that the command returns only one site without making unnecessary requests.

Written by the indexing model from the issue text.

Assessment

Tech stack
powershell
Domain
api, cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.