msgraph-sdk-powershell
msgraph-sdk-powershell copied to clipboard
-All parameter should automatically set -PageSize=999
When listing all items, it's much more efficient to query the maximum Microsoft Graph PageSize, 999 items ($top parameter), instead of the default 20.
The -All queries could be up to 50 times faster, as it reduces roundtrips using @odata.nextLink.
If a query has -All parameter, it should automatically set -PageSize 999 if not otherwise specified in the query.
Good idea!
@Licantrop0 Why have you mentioned the $top parameter when the -PageSize is responsible for the page size?
@Licantrop0 Why have you mentioned the $top parameter when the -PageSize is responsible for the page size?
because PageSize sets the Top parameter, see: https://github.com/microsoftgraph/msgraph-sdk-powershell/blob/bf523777647903ef7098e0a5dd5d3e98703c08eb/tools/Custom/ListCmdlet.cs#L119C12-L123C14
@petrhollayms, I discovered that this was asked already a while ago and it breaks some scenarios, see: https://github.com/microsoftgraph/msgraph-sdk-powershell/pull/1230 and: https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/1248, maybe we should reconsider this.
@Licantrop0 You are right. -PageSize sets the $top query parameter. What confused me is that $top behaves differently depending on the other used parameters.
If -Top is used without the -Pagesize, -Top sets the $top. If -Top is used with the -Pagesize, -Pagesize sets $top, but -Top controls how many items will be returned.
-PageSize cannot be greater than 999. However, -Top can be greater than 999, and command like Get-MgUser -Top 1000 -PageSize 999 will return 1000 users making 2 requests (999+1) to the MSGraph endpoint. (I assume this. I haven't tested it.)
It's possible to specify -Top and -All at the same time, but I don't understand why would you do that. -Top and -All should be in different parameter sets, right?
@peombwa wrote that code and he would be the best explaining the behavior. FYI @SteveMutungi254