MSGraph – Get-MgUser

Count all users

Get-MgUser -All | Measure-Object | Select-Object -ExpandProperty Count

user account status

Get-MgUser -UserId "xxx" -Property Id, DisplayName, UserPrincipalName, AccountEnabled | Select-Object Id, DisplayName, UserPrincipalName, AccountEnabled

Get-MgUser -All -Filter "accountEnabled eq true" -Property Id, DisplayName, UserPrincipalName, AccountEnabled | Select-Object Id, DisplayName, UserPrincipalName, AccountEnabled

cloud users including guests

Get-MgUser -All -Filter "OnPremisesSyncEnabled ne true" -ConsistencyLevel eventual -CountVariable CountVar

cloud users excluding guests

Get-MgUser -All -Filter "OnPremisesSyncEnabled ne true and UserType eq 'Member'" -ConsistencyLevel eventual -CountVariable CountVar

licensed users

Get-MgUser -All -Filter "assignedLicenses/`$count ne 0 and userType eq 'Member'" -ConsistencyLevel eventual -CountVariable Records

on-premises synced users

Get-MgUser -All -Filter "OnPremisesSyncEnabled eq true" | Sort-Object DisplayName

manager

Get-MgUser -All -ExpandProperty Manager | Select-Object @{Name = 'Manager'; Expression = { $_.Manager.AdditionalProperties.mail } }

sign-in activity

Get-MgUser -All -Property SignInActivity | Select-Object -ExpandProperty SignInActivity

company name

Get-MgUser -All -Property DisplayName, UserPrincipalName, CompanyName | Select-Object DisplayName, UserPrincipalName, CompanyName