Skip to content

Instantly share code, notes, and snippets.

@MatthewJDavis
Last active June 11, 2021 22:22
Show Gist options
  • Select an option

  • Save MatthewJDavis/a802fc8a39bfa2990ce559f3eb0dacef to your computer and use it in GitHub Desktop.

Select an option

Save MatthewJDavis/a802fc8a39bfa2990ce559f3eb0dacef to your computer and use it in GitHub Desktop.
PowerShell MS Graph Module useful commans
# Don't use MS Account, use account in AzureAD
Install-Module microsoft.graph
Select-MgProfile -Name "beta"
Connect-MgGraph -Scopes "User.Read.All"
# View auth commands
Get-Command -Module Microsoft.Graph.Authentication
# Check scopes
# Permission: https://docs.microsoft.com/en-us/graph/permissions-reference
Get-MgContext | Select -ExpandProperty scopes
# Display all Users
Get-MgUser
# Filter by DisplayName
Get-MgUser -Filter "DisplayName eq 'demo1'" | Format-List *
Get-MgUser -Filter "startswith(displayName,'Matt')"
Get-MgUser -Filter "UserType eq 'Member'"
Get-MgUser -Filter "UserType eq 'Guest'"
# Filter by licence
Get-MgUser -Filter "assignedLicenses/any(x:x/skuId eq efccb6f7-5641-4e0e-bd10-b4976e1bf68e)" -All # ENTERPRISE MOBILITY + SECURITY E3
# Disabled users
Get-MgUser -Filter 'accountEnabled eq false'
Disconnect-MgGraph
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment