Get-MgUser is a Microsoft Graph PowerShell cmdlet used to retrieve details of users in a Microsoft 365 tenant. It can fetch properties like Display Name, User Principal Name (UPN), account status, license assignment, department, and more.
Get-MgUser is essential for automating Microsoft 365 user management tasks. Admins can retrieve user records in bulk, filter based on specific attributes, and generate reports—all without manually navigating the Microsoft 365 Admin Center. This enhances efficiency, accuracy, and scalability in managing cloud environments.
The Get-MgUser cmdlet can be used with no parameters to list users, or with the -UserId parameter to retrieve a specific user by their User ID or UPN.
Syntax:
Get-MgUser -UserId <UserId or UPN>
You can also use the -All, -Filter, and -ConsistencyLevel parameters to perform broader queries.
Get-MgUser
Retrieves a list of users with default paginated output and no filters.
Get-MgUser -All
Retrieves all users in the tenant, bypassing pagination.
Get-MgUser -UserId <user-id>
Fetches detailed information about a specific user using their object ID.
Get-MgUser -UserId <UPN>
Retrieves a user’s details using their User Principal Name (email address).
Get-MgUser -Filter "Department eq 'Sales'"
Lists all users assigned to the Sales department.
Get-MgUser -All -Filter "assignedLicenses/`$count ne 0 and userType eq 'Member'" -ConsistencyLevel eventual -CountVariable Records
Gets all licensed member users in the tenant.
Get-MgUser -All -Filter "assignedLicenses/`$count eq 0 and userType eq 'Member'" -ConsistencyLevel eventual -CountVariable Records
Retrieves all unlicensed member users in the tenant.
Get-MgUser -All -Filter "startsWith(DisplayName,'A')"
Returns users whose display names begin with the letter A.
Key Point | Details |
Cmdlet Name | Get-MgUser |
Purpose | Retrieve Microsoft 365 user details |
Ideal For | Admins managing users via automation |
Included In? | Microsoft Graph PowerShell SDK |
Access Method | PowerShell with Connect-MgGraph session |
Integrates With | Microsoft Graph API, Azure AD, Microsoft 365 services |
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex