msgraph-sdk-powershell icon indicating copy to clipboard operation
msgraph-sdk-powershell copied to clipboard

-All parameter should automatically set -PageSize=999

Open Licantrop0 opened this issue 1 year ago • 6 comments

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.

Licantrop0 avatar May 31 '24 20:05 Licantrop0

Good idea!

12Knocksinna avatar Jun 02 '24 20:06 12Knocksinna

@Licantrop0 Why have you mentioned the $top parameter when the -PageSize is responsible for the page size?

alexandair avatar Jul 14 '24 17:07 alexandair

@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

Licantrop0 avatar Jul 14 '24 19:07 Licantrop0

@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 avatar Jul 14 '24 19:07 Licantrop0

@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?

alexandair avatar Jul 14 '24 19:07 alexandair

@peombwa wrote that code and he would be the best explaining the behavior. FYI @SteveMutungi254

Licantrop0 avatar Jul 15 '24 10:07 Licantrop0