msgraph-sdk-powershell
msgraph-sdk-powershell copied to clipboard
Support per module default output formatting (Get-MgUser's and Get-MgBetaUser's UserType property: Now you see it, now you don't)
Different versions of SDK and Graph API cause different, inconsistent, behavior for the UserType property.
SDK v1, v1.0 endpoint: Get-MgUser doesn't return UserType by default SDK v1, beta endpoint: Get-MgUser returns and displays UserType by default
SDK v2, v1.0 endpoint: Get-MgUser doesn't return UserType by default SDK v2, beta endpoint: Get-MgBetaUser returns UserType, but it's not displayed in the output by default
Behavior also changes when -Property is used, if we get the specified user or list all users
PS> get-mgbetauser -property signinactivity -userid ac4de573-e369-4dcb-bbd2-170c4a0b667c | select usertype
UserType
--------
PS> get-mgbetauser -property signinactivity | select usertype
UserType
--------
Member
Member
...
Thanks for following up on this.
This is a behavior with the API that's reproducible through Graph Explorer as well. Calling the command with -Debug will return the raw HTTP response from the API.
The API does not return all user properties when fetching a single user and signInActivity is exclusively specified in the $select/-Property:
vs
As a workaround, you can explicitly include userType in the $select/-Property - -property signinactivity, userType.
Please open a question/ticket at https://developer.microsoft.com/en-us/graph/support as this is a service issue. Please include the requestId and date of the affected calls in your ticket/question. See Microsoft Graph PowerShell module troubleshooting guide for more details.
This repository is intended for issues related to the functionality of the module. We may not be the best place to answer some queries that are tied to the functionality of the API.
@peombwa This is a PowerShell issue:
SDK v2, beta endpoint: Get-MgBetaUser returns UserType, but it's not displayed in the output by default
@alexandair, this is covered in the known issues - https://github.com/microsoftgraph/msgraph-sdk-powershell#known-issues. Since we use CLR types, only a handful of preselected properties are shown on your terminal by default. You can pipe the command's output to PowerShell's Format-* commands to show all properties/ format the response to your liking.
The change was made as part https://github.com/microsoftgraph/msgraph-sdk-powershell/pull/2002 to remove the property from the v1.0 response. The output display format config (AutoREST directives) only supports formatting by type names, we can't have unique output display format for v1.0 and beta types:
directive:
- where:
model-name: ^MicrosoftGraphUser\d*$
set:
format-table:
properties:
- DisplayName
- Id
- Mail
- UserPrincipalName
@peombwa I'm confused now. Why can't we have the same output in SDK v1 and SDK v2 for beta endpoint?
SDK v1, beta endpoint: Get-MgUser returns and displays UserType by default SDK v2, beta endpoint: Get-MgBetaUser returns UserType, but it's not displayed in the output by default
SDK v1, v1.0 endpoint: Get-MgUser doesn't return UserType by default SDK v2, v1.0 endpoint: Get-MgUser doesn't return UserType by default
I'm confused now. Why can't we have the same output in SDK v1 and SDK v2 for beta endpoint?
Here is why:
The change was made as part https://github.com/microsoftgraph/msgraph-sdk-powershell/pull/2002 to remove the property from the v1.0 response. The output display format config (AutoREST directives) only supports formatting by type names, we can't have unique output display format for v1.0 and beta types. The config is global and applies to both v1.0 and beta types - https://github.com/microsoftgraph/msgraph-sdk-powershell/blob/dev/src/readme.graph.default.output.md - i.e., user, group, etc in both v1.0 and beta.
The change was part of the discussion at https://github.com/microsoftgraph/msgraph-sdk-powershell/discussions/1754. The properties that are currently shown in the default output are returned by default in both v1.0 and beta.
v1.0: TypeName: Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser beta: TypeName: Microsoft.Graph.Beta.PowerShell.Models.MicrosoftGraphUser
Could you use the full type names instead of model-name: ^MicrosoftGraphUser\d*$?
In SDK v1, you managed to get different default output when v1.0 and beta shared Microsoft.Graph.Users.format.ps1xml file, but now in SDK v2, when we have separated Microsoft.Graph.Users.format.ps1xml files for v1.0 and beta, we cannot have different default outputs. I'm amazed.
v1.0: TypeName: Microsoft.Graph.PowerShell.Models.MicrosoftGraphUser beta: TypeName: Microsoft.Graph.Beta.PowerShell.Models.MicrosoftGraphUser
Could you use the full type names instead of
model-name: ^MicrosoftGraphUser\d*$?
Unfortunately AutoREST's directives do not support using type names with namespaces in the model-name. This is why we are limited to a shared type name based default output format.
In SDK v1, you managed to get different default output when v1.0 and beta shared Microsoft.Graph.Users.format.ps1xml file, but now in SDK v2, when we have separated Microsoft.Graph.Users.format.ps1xml files for v1.0 and beta, we cannot have different default outputs. I'm amazed.
The default output for v1.0 and beta were always the same in SDK v1:
I'll open an issue on AutoREST.PowerShell's end to see if they can support using namespaces in model-name for their directives as it would help address this issue.
The default output for v1.0 and beta is not the same in SDK v1:
PS> select-mgprofile v1.0
PS> get-mguser -top 1
Id DisplayName Mail UserPrincipalName UserType
-- ----------- ---- ----------------- --------
ac4de573-e369-4dcb-bbd2-170c4a0b667c Adele Mance [email protected]
PS> select-mgprofile beta
PS> get-mguser -top 1
Id DisplayName Mail UserPrincipalName UserType
-- ----------- ---- ----------------- --------
ac4de573-e369-4dcb-bbd2-170c4a0b667c Adele Mance [email protected] Member
And now, in SDK v2, column UserType is missing for both v1.0 and beta.
PS> get-mguser -top 1
DisplayName Id Mail UserPrincipalName
----------- -- ---- -----------------
Adele Mance ac4de573-e369-4dcb-bbd2-170c4a0b667c [email protected]
PS> get-mgbetauser -top 1
DisplayName Id Mail UserPrincipalName
----------- -- ---- -----------------
Adele Mance ac4de573-e369-4dcb-bbd2-170c4a0b667c [email protected]
The default output for v1.0 and beta is not the same in SDK v1:
PS> select-mgprofile v1.0 PS> get-mguser -top 1 Id DisplayName Mail UserPrincipalName UserType -- ----------- ---- ----------------- -------- ac4de573-e369-4dcb-bbd2-170c4a0b667c Adele Mance [email protected] PS> select-mgprofile beta PS> get-mguser -top 1 Id DisplayName Mail UserPrincipalName UserType -- ----------- ---- ----------------- -------- ac4de573-e369-4dcb-bbd2-170c4a0b667c Adele Mance [email protected] Member
I'm confused. Are you talking about the API response difference or SDK default output format difference in SDK v1? Your original question was:
In SDK v1, you managed to get different default output when v1.0 and beta shared Microsoft.Graph.Users.format.ps1xml ...
Of which, I answered you above with the screenshots - https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2144#issuecomment-1633303900. The default output format for a user type was the same in v1.0 and beta in SDK v1 as shown in the screenshots.
And now, in SDK v2, column UserType is missing for both v1.0 and beta.
Answered above - https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2144#issuecomment-1633252190:
The change was made as part https://github.com/microsoftgraph/msgraph-sdk-powershell/pull/2002 to remove the property from the v1.0 response. The output display format config (AutoREST directives) only supports formatting by type names, we can't have unique output display format for v1.0 and beta types. The config is global and applies to both v1.0 and beta types - https://github.com/microsoftgraph/msgraph-sdk-powershell/blob/dev/src/readme.graph.default.output.md - i.e., user, group, etc in both v1.0 and beta.
You are correct. I wasn't precise.
Looking at the different versions of SDKs and endpoints, we have 4 different combinations of the default output columns and response values for UserType.
And you are telling me that nothing can be done, because of the limitations of the directives.
Get Outlook for Androidhttps://aka.ms/AAb9ysg
From: Peter Ombwa @.> Sent: Thursday, July 13, 2023 1:22:07 AM To: microsoftgraph/msgraph-sdk-powershell @.> Cc: Aleksandar Nikolić @.>; Mention @.> Subject: Re: [microsoftgraph/msgraph-sdk-powershell] Get-MgUser's and Get-MgBetaUser's UserType property: Now you see it, now you don't (Issue #2144)
The default output for v1.0 and beta is not the same in SDK v1:
PS> select-mgprofile v1.0 PS> get-mguser -top 1
Id DisplayName Mail UserPrincipalName UserType
ac4de573-e369-4dcb-bbd2-170c4a0b667c Adele Mance @.***
PS> select-mgprofile beta PS> get-mguser -top 1
Id DisplayName Mail UserPrincipalName UserType
ac4de573-e369-4dcb-bbd2-170c4a0b667c Adele Mance @.*** Member
I'm confused. Are you talking about the API response difference or SDK default output format difference in SDK v1? Your original questionhttps://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2144#issuecomment-1633284745 was:
In SDK v1, you managed to get different default output when v1.0 and beta shared Microsoft.Graph.Users.format.ps1xml ...
Of which, I answered you above with the screenshots - #2144 (comment)https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2144#issuecomment-1633303900. The default output format for a user type was the same in v1.0 and beta in SDK v1 as shown in the screenshots.
And now, in SDK v2, column UserType is missing for both v1.0 and beta.
Answered above - #2144 (comment)https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2144#issuecomment-1633252190:
The change was made as part #2002https://github.com/microsoftgraph/msgraph-sdk-powershell/pull/2002 to remove the property from the v1.0 response. The output display format config (AutoREST directives) only supports formatting by type names, we can't have unique output display format for v1.0 and beta types. The config is global and applies to both v1.0 and beta types - https://github.com/microsoftgraph/msgraph-sdk-powershell/blob/dev/src/readme.graph.default.output.md - i.e., user, group, etc in both v1.0 and beta.
— Reply to this email directly, view it on GitHubhttps://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2144#issuecomment-1633326984, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAX5RXAMHIEFCHYRWZMOWFDXP4WR7ANCNFSM6AAAAAA2E7IRME. You are receiving this because you were mentioned.Message ID: @.***>
That's right! I've opened a feature request at https://github.com/Azure/autorest.powershell/issues/1191 to address the directive limitation. The feature request should allow for a more localized default output format as suggested at https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2144#issuecomment-1633284745.
While we are at it, what can be done for the default output for MicrosoftGraphDirectoryObject type?
Outputting only ID, by default, and nothing else is a terrible user experience. PowerShell supports ETS (Extensible Type System) and it's time (for SDK v3) to unwrap AdditionalProperties and fetch some useful properties that would make default output usable and user-friendly.
Sorry for the late response.
The plan is to tackle heterogeneous collections in v3 via OpenAPI's discriminator support - https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/19#issuecomment-595575996. Discriminator support will effectively eliminate the need to rely on additionalProperties to retrieve derived type properties.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.
What does "as not planned" mean? This won't be fixed in v3?
Sorry about that. The issue got closed by error.
I'll rename the title of the issue to "Support per module default output formatting" for discoverability.