If you're managing a Microsoft 365 environment, chances are you need to retrieve user details often. Whether it's for auditing, reporting, or user management, the Get-MgUser cmdlet in Microsoft Graph PowerShell is a powerful tool to fetch user information quickly and efficiently. This guide will help you understand how to use Get-MgUser with simple examples.
Get-MgUser is a Microsoft Graph PowerShell cmdlet that allows administrators to retrieve details about Microsoft 365 users. It replaces the older Get-AzureADUser cmdlet and provides more flexibility and security using Microsoft Graph API.
With Get-MgUser, you can:
Microsoft 365 administrators prefer Get-MgUser because:
The basic syntax for Get-MgUser is:
Get-MgUser [-UserId <String>] [-All] [-Filter <String>]
Get-MgUser -All
This command fetches all users in your Microsoft 365 tenant.
Get-MgUser -UserId "admin@contoso.com"
Get-MgUser -UserId "1111-2222-3333-4444"
Instead of an email address, you can also use the unique Object ID assigned to a user in Microsoft Entra ID.
Get-MgUser -All -Filter "userType eq 'Guest'"
This command fetches all the guest users (or external users) in the tenant.
UserType
≠ Licensing StatusUserType
property indicates whether a user is a Guest or a Member, but it does not reflect licensing status.UserType
checks with assignedLicenses/$count
logic.
Get-MgUser -All -Filter "accountEnabled eq false"
This command fetches all the disabled user accounts in the tenant.
Get-MgUser -UserId "admin@contoso.com" -Property DisplayName,Mail
-Property
Get-MgUser
returns a limited set of user properties. To retrieve only the fields you need — such as DisplayName
, UserPrincipalName
, or AccountEnabled
— use the -Property
parameter.Get-MgUser -All -Filter "department eq 'Sales'"
The Get-MgUser cmdlet is an essential tool for Microsoft 365 administrators looking to manage users efficiently. Whether you're retrieving a single user or querying all users in your organization, this cmdlet offers flexibility, security, and precision. Start using Get-MgUser today to streamline your M365 management!
© Your Site Name. All Rights Reserved. Design by HTML Codex