get-mguser is not giving the data
Thanks for reporting the bug. Please ensure you've gone through the following checklist before opening an issue:
- Make sure you can reproduce this issue using the latest released version of Microsoft.Graph or Microsoft.Graph.Beta.
- Please search the existing issues to see if there has been a similar issue filed.
- For issues related to authentication and service errors, please refer to our troubleshooting guide. For service issues, please open a question at https://developer.microsoft.com/graph/support.
Describe the bug
A clear and concise description of what the bug is. When we run get-mguser to get the information on the users in the tenant the following attributes are null. The following are the attributes we noticed are null
Usertype CreatedDateTime AssignedLicenses AccountEnabled ShowInAddressList
To Reproduce Steps to reproduce the behavior: Get-MgUser -all | select-object -Property userprincipalname,DisplayName,UserType,@{L="CreatedDateTimeUTC";E={$.CreatedDateTime}}, JobTitle, Department,AccountEnabled, @{name='IsLicensed';expression={if($.AssignedLicenses){$TRUE}else{$False}}},@{L="ObjectID";E={$.id}}, OnPremisesImmutableId, ExternalUserState,@{L="SignInName";E={$.mail}},CreationType,ShowInAddressList
There is no error. the fields are just empty Expected behavior
A clear and concise description of what you expected to happen. We expect to see information on this attributes as they are important attributes for users Usertype CreatedDateTime AssignedLicenses AccountEnabled ShowInAddressList
Debug Output
Run the problematic command with
-Debugand paste the resulting debug stream below. ⚠ ATTENTION: Be sure to remove any sensitive information that may be in the logs. Get-MgUser -UserId remove -debug | select-object -Property userprincipalname,DisplayName,UserType,@{L="CreatedDateTimeUTC";E={$.CreatedDateTime}}, JobTitle, Department,AccountEnabled, @{name='IsLicensed';expression={if($.AssignedLicenses){$TRUE}else{$False}}},@{L="ObjectID";E={$.id}}, OnPremisesImmutableId, ExternalUserState,@{L="SignInName";E={$.mail}},CreationType,ShowInAddressList DEBUG: [CmdletBeginProcessing]: - Get-MgUser begin processing with parameterSet 'Get'.
Confirm Continue with this operation? [Y] Yes [A] Yes to All [H] Halt Command [S] Suspend [?] Help (default is "Y"): A DEBUG: [Authentication]: - AuthType: 'AppOnly', TokenCredentialType: 'ClientCertificate', ContextScope: 'Process', AppName: 'UMIT ISA App MSGraph'. DEBUG: [Authentication]: - Scopes: [Device.Read.All, RoleManagement.Read.Directory, Group.Read.All, Sites.Read.All, Directory.Read.All, RoleManagement.Read.All, User.Read.All, Application.Read.All, RoleAssignmentSchedule.Read.Directory, Reports.Read.All]. DEBUG: ============================ HTTP REQUEST ============================
HTTP Method: GET
Absolute Uri: https://graph.microsoft.com/v1.0/users/[email protected]
Headers: FeatureFlag : 00000043 Cache-Control : no-store, no-cache User-Agent : Mozilla/5.0,(Windows NT 10.0; Microsoft Windows 10.0.17763; en-US),PowerShell/5.1.17763.5328
Body:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code: OK
Headers: Transfer-Encoding : chunked Vary : Accept-Encoding Strict-Transport-Security : max-age=31536000 request-id : 265a3c60-3867-4bd1-8e79-e381f01fa88e client-request-id : e6a3c7da-d5b1-41fd-93f6-5e57bc1ebf82 x-ms-ags-diagnostic : {"ServerInfo":{"DataCenter":"East US 2","Slice":"E","Ring":"5","ScaleUnit":"004","RoleInstance":"BN1PEPF00003BB8"}} x-ms-resource-unit : 1 OData-Version : 4.0 Cache-Control : no-cache Date : Thu, 01 Feb 2024 21:53:36 GMT
Body: { "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity", "businessPhones": [ "+1 (305) 2842442" ], "displayName": "remove", "givenName": "remove", "jobTitle": "remove", "mail": "remove", "mobilePhone": null, "officeLocation": "remove", "preferredLanguage": null, "surname": "remove", "userPrincipalName": "remove", "id": "remove" }
UserPrincipalName : remove DisplayName : remove UserType : CreatedDateTimeUTC : JobTitle : remove Department : AccountEnabled : IsLicensed : remove ObjectID : remove OnPremisesImmutableId : ExternalUserState : SignInName : remove CreationType : ShowInAddressList :
Module Version
Please run
Get-Module Microsoft.Graph*after cmdlet execution and paste the output below. If a module cannot be installed or imported, please runGet-Module -ListAvailableand paste the output. 2.12.0 Microsoft.Graph.Users
Environment Data
Please run
$PSVersionTableand paste the output below. If running the Docker container image, indicate the tag of the image used and the version of Docker engine. Name Value
PSVersion 5.1.17763.5328 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.17763.5328 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1 Screenshots
If applicable, add screenshots to help explain your problem.
Additional context
Add any other context about the problem here. This was working in the module 1.28.0 once we upgraded to the new module it stop
Hi Lajuyu,
Not all properties are returned by the Graph API by default. To see what I mean, conduct the following test (after connecting using Connect-MgGraph),
$User = <Your test user's UPN here>
Get-MgUser -UserID $User | Format-List
When you scroll down and look at the properties such as UserType, and CreatedDateTime, you'll notice that they are empty.
To resolve this, when you call your Get-MgUser query, you'll need to specify all the properties that you need. i.e. Get-MgUser -all -Property UserPrincipalName,DisplayName,UserType,CreatedDateTime,JobTitle,Department,AccountEnabled,AssignedLicences,Id,OnPremisesImmutableId,ExternalUserState,Mail,CreationType,ShowInAddressList | select-object -Property userprincipalname,DisplayName,UserType,@{L="CreatedDateTimeUTC";E={$.CreatedDateTime}}, JobTitle, Department,AccountEnabled, @{name='IsLicensed';expression={if($.AssignedLicenses){$TRUE}else{$False}}},@{L="ObjectID";E={$.id}}, OnPremisesImmutableId, ExternalUserState,@{L="SignInName";E={$.mail}},CreationType,ShowInAddressList
Can you also please update some of the information in your debug? You've included some information in there which should be removed. Specifically the businessPhones, and your Absolute Uri
Why has this change? My original script worked for months and why does it work using the beta (get-mgbetauser)? There are still properties that don't get any information like AssigendLicenses. That used to have information before.
Judith Tanner
Manager
Information Technology
University of Miami
P: (305) 284-4278
[cid:a2fbc1c4-4534-417f-bc82-234e0046463f]
From: SeniorConsulting @.> Sent: Thursday, February 1, 2024 10:34 PM To: microsoftgraph/msgraph-sdk-powershell @.> Cc: Tanner, Judith @.>; Author @.> Subject: [EXTERNAL] Re: [microsoftgraph/msgraph-sdk-powershell] get-mguser is not giving the data (Issue #2561)
CAUTION: This email originated from outside the organization. DO NOT CLICK ON LINKS or OPEN ATTACHMENTS unless you know and trust the sender.
Hi Lajuyu,
Not all properties are returned by the Graph API by default. To see what I mean, conduct the following test (after connecting using Connect-MgGraph),
$User = <Your test user's UPN here> Get-MgUser -UserID $User | Format-List
When you scroll down and look at the properties such as UserType, and CreatedDateTime, you'll notice that they are empty.
To resolve this, when you call your Get-MgUser query, you'll need to specify all the properties that you need. i.e. Get-MgUser -all -Property UserPrincipalName,DisplayName,UserType,CreatedDateTime,JobTitle,Department,AccountEnabled,AssignedLicences,Id,OnPremisesImmutableId,ExternalUserState,Mail,CreationType,ShowInAddressList | select-object -Property userprincipalname,DisplayName,UserType,@{L="CreatedDateTimeUTC";E={$.CreatedDateTime}}, JobTitle, Department,AccountEnabled, @{name='IsLicensed';expression={if($.AssignedLicenses){$TRUE}else{$False}}},@{L="ObjectID";E={$.id}}, OnPremisesImmutableId, ExternalUserState,@{L="SignInName";E={$.mail}},CreationType,ShowInAddressList
— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2561*issuecomment-1922745674__;Iw!!KVu0SnhVq1hAFvslES2Y!K3stjMUYGRyvi-hWkWnNZEYg-i7-oJazNeAf5jj2X3nqEs8ECJhV8XHVOJKLhO9JjISww5PKMvRoMkQWCQzcfrI$, or unsubscribehttps://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AK5MNVPUGSY55SVOJ4MWCHLYRRNCVAVCNFSM6AAAAABCVVDSQ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRSG42DKNRXGQ__;!!KVu0SnhVq1hAFvslES2Y!K3stjMUYGRyvi-hWkWnNZEYg-i7-oJazNeAf5jj2X3nqEs8ECJhV8XHVOJKLhO9JjISww5PKMvRoMkQWoQMw8f0$. You are receiving this because you authored the thread.Message ID: @.***>
What has happened, is that you've upgraded the module version from 1.x to 2.12.0. You're no longer querying the beta endpoint. This is also reflected in the Absolute URI, which shows that you're hitting V1.
For more information about the upgrade from v1.x to 2.x of the PowerShell Graph SDK, please view more in the readme: https://github.com/microsoftgraph/msgraph-sdk-powershell#notes
In short, you'll need to get rid of your Select-MgProfile cmdlet, and instead use Get-MgBetaUser. Bear in mind that you shouldn't be using the beta endpoint for production workloads.
If we shouldn’t use the beta then what PowerShell will provide us with the attributes we need Created date User type Assigned license Showinaddresslist
Thanks
Judy
Get Outlook for iOShttps://aka.ms/o0ukef
From: SeniorConsulting @.> Sent: Tuesday, February 6, 2024 2:39:26 PM To: microsoftgraph/msgraph-sdk-powershell @.> Cc: Tanner, Judith @.>; Author @.> Subject: [EXTERNAL] Re: [microsoftgraph/msgraph-sdk-powershell] get-mguser is not giving the data (Issue #2561)
CAUTION: This email originated from outside the organization. DO NOT CLICK ON LINKS or OPEN ATTACHMENTS unless you know and trust the sender.
What has happened, is that you've upgraded the module version from 1.x to 2.12.0. You're no longer querying the beta endpoint. This is also reflected in the Absolute URI, which shows that you're hitting V1.
For more information about the upgrade from v1.x to 2.x of the PowerShell Graph SDK, please view more in the readme: https://github.com/microsoftgraph/msgraph-sdk-powershell#noteshttps://urldefense.com/v3/__https://github.com/microsoftgraph/msgraph-sdk-powershell*notes__;Iw!!KVu0SnhVq1hAFvslES2Y!NjbS4jQnu4Y_zYPcuUZ9SCzmu09RLo0y1PRu_a7lg8HKGAFVG3COvRYh4EKDQUt9MrNxIvDYPl0g6PPps8wOPXY$
In short, you'll need to get rid of your Select-MgProfile cmdlet, and instead use Get-MgBetaUser. Bear in mind that you shouldn't be using the beta endpoint for production workloads.
— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https://github.com/microsoftgraph/msgraph-sdk-powershell/issues/2561*issuecomment-1930629248__;Iw!!KVu0SnhVq1hAFvslES2Y!NjbS4jQnu4Y_zYPcuUZ9SCzmu09RLo0y1PRu_a7lg8HKGAFVG3COvRYh4EKDQUt9MrNxIvDYPl0g6PPpqg7hoOI$, or unsubscribehttps://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AK5MNVP5GTGUXWNHR44225TYSKBG5AVCNFSM6AAAAABCVVDSQ2VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMZQGYZDSMRUHA__;!!KVu0SnhVq1hAFvslES2Y!NjbS4jQnu4Y_zYPcuUZ9SCzmu09RLo0y1PRu_a7lg8HKGAFVG3COvRYh4EKDQUt9MrNxIvDYPl0g6PPpfvsJ1Ec$. You are receiving this because you authored the thread.Message ID: @.***>
Hi Judy,
My first comment covered off the parameter to use to include the properties you're interested in, i.e.
Get-MgUser -all -Property UserPrincipalName,DisplayName,UserType,CreatedDateTime,JobTitle,Department,AccountEnabled,AssignedLicences,Id,OnPremisesImmutableId,ExternalUserState,Mail,CreationType,ShowInAddressList
In your script, I believe it would look like:
Get-MgUser -all -Property UserPrincipalName,DisplayName,UserType,CreatedDateTime,JobTitle,Department,AccountEnabled,AssignedLicences,Id,OnPremisesImmutableId,ExternalUserState,Mail,CreationType,ShowInAddressList | select-object -Property userprincipalname,DisplayName,UserType,@{L="CreatedDateTimeUTC";E={$.CreatedDateTime}}, JobTitle, Department,AccountEnabled, @{name='IsLicensed';expression={if($.AssignedLicenses){$TRUE}else{$False}}},@{L="ObjectID";E={$.id}}, OnPremisesImmutableId, ExternalUserState,@{L="SignInName";E={$.mail}},CreationType,ShowInAddressList
Thanks for the info this is now working