msgraph-sdk-powershell
msgraph-sdk-powershell copied to clipboard
Feature Request: -As parameter to cast objects to a type as part of the query
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. 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.
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.