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

Feature Request: -As parameter to cast objects to a type as part of the query

Open JustinGrote opened this issue 3 years ago • 1 comments

Synopsis

Some cmdlets like get-mggroupmember support an additional REST path to specify the type of object to return instead of just DirectoryObject https://docs.microsoft.com/en-us/graph/api/group-list-members?view=graph-rest-1.0&tabs=http#example-4-use-searchand-odata-cast-to-get-user-membership-in-groups-with-display-names-that-contain-the-letters-pr-including-a-count-of-returned-objects (Example #4)

Recommended Implementation

Support a -As parameter that either has an enum or just takes a string of supported types that will append this to the request URI, and type it to the same appropriate type in powershell models.

Workaround

[MicrosoftGraphUser1[]]$result = (Invoke-MgGraphRequest -uri 'v1.0/groups/68216d21-752a-4241-8782-d58a960724a3/members/microsoft.graph.user?$select=userprincipalname').Value

JustinGrote avatar Feb 02 '22 03:02 JustinGrote

@JustinGrote. Thanks for taking the time to open this issue. Your proposal of adding a -As parameter of the derived types as an enum sounds like a good idea. We will first need to implement #19, then add -As parameter to all commands that support OData cast.

The SDK does not currently support OData cast due to a lack of derived types in the CSDL metadata/OpenAPI file. We are tracking OData cast support via OpenAPI discriminator in #19.

peombwa avatar Mar 31 '22 22:03 peombwa

Closing as duplicate of https://github.com/microsoftgraph/microsoft-graph-devx-api/issues/1228.

The implementation will be something like Get-MgGroupMemberAsUser due to how the API is structured and what's supported by the code generator.

peombwa avatar Apr 07 '23 19:04 peombwa