Microsoft Graph PowerShell Command Builder (Azure AD / Entra ID)

Build ready-to-run Microsoft Graph PowerShell commands for Entra ID users, groups, MFA, licensing, roles, devices and audit logs. Free, no sign-in.

Advertisement

Azure AD / Microsoft Entra ID PowerShell Command Builder

This tool builds ready-to-run PowerShell for Microsoft Entra ID (still widely searched for as “Azure AD”). Pick a task — create a user, reset a password, audit MFA registration, list unused licences, dump sign-in logs — fill in the one or two values it needs, and copy a command that works as-is. It also tells you which Microsoft Graph permission scopes that command requires, which is the single most common reason a copied snippet fails with Insufficient privileges.

Everything runs in your browser. Nothing you type is sent anywhere, and no tenant is contacted — the tool generates text, it does not execute anything. That means you can safely paste a real UPN or tenant ID into the fields to get a command you can run without editing.

The Module Landscape Has Changed — Read This First

If you are following an older blog post, the commands in it are probably dead. The AzureAD and MSOnline PowerShell modules were retired on 30 March 2025. Cmdlets such as Connect-AzureAD, Get-AzureADUser, Set-AzureADUser and Get-MsolUser no longer have a supported service behind them. The replacement is the Microsoft Graph PowerShell SDK, whose cmdlets all carry an Mg noun prefix: Get-MgUser, New-MgGroup, Get-MgAuditLogSignIn, and so on.

This tool has a Graph / legacy toggle. Graph is the default and is what you should copy. The legacy view exists purely so you can recognise an old script and find its modern equivalent side by side — every legacy snippet is labelled as deprecated. Use it as a translation table when you inherit a scripts folder nobody has touched since 2021.

What the Tool Covers

Tasks are grouped into eight tabs:

  • Connect & Setup — installing and updating the module, interactive sign-in, device code flow for machines without a browser, app-only certificate authentication for unattended automation, checking the current context, and disconnecting cleanly.
  • Users — retrieve one user or list all, create, update job title and department, disable or re-enable an account, reset a password, delete, and recover a soft-deleted user from the directory recycle bin.
  • Groups — create security groups and Microsoft 365 groups, add and remove members, list membership, and list a user’s group memberships.
  • MFA & Auth — enumerate a user’s registered authentication methods so you can find accounts with no strong factor registered.
  • Licensing — list subscribed SKUs with consumed versus available units, and assign or remove licences.
  • Roles & Admin — list directory roles and their members, look up role definitions, and create a role assignment.
  • Reporting & Auditing — sign-in logs, directory audit logs, and inactive-account reports driven by a threshold you choose in days, with optional CSV export.
  • Devices — list registered devices, find devices owned by a specific user, and remove a stale device object.

How to Use It

  1. Pick a tab matching the object you are working with — users, groups, licences, devices.
  2. Select the task. Each task shows a short description of what it does before you commit to it.
  3. Fill in the placeholders. Depending on the task that might be a user principal name, a group display name, an inactivity threshold in days, or a tenant ID, application ID and certificate thumbprint for app-only auth.
  4. Check the required scopes. The tool lists the Graph permissions the command needs. Pass exactly those to Connect-MgGraph rather than requesting everything.
  5. Copy and run. Test against a single test account before running anything that loops over your whole directory.

Getting Connected

Install the SDK once, from an elevated or user-scoped PowerShell session:

Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force

PowerShell 7 or later is recommended on every platform; Windows PowerShell 5.1 works but needs .NET Framework 4.7.2 and an execution policy of RemoteSigned or looser. Installing the umbrella Microsoft.Graph module pulls in dozens of sub-modules, so on a constrained build agent you may prefer to install only the sub-modules you need — Microsoft.Graph.Authentication always comes along.

Then authenticate. Interactive sign-in is the normal path for ad-hoc administration:

Connect-MgGraph -Scopes "User.Read.All", "Group.Read.All"

On a server or SSH session with no browser, use device code flow, which prints a code you enter on another machine:

Connect-MgGraph -Scopes "User.Read.All" -UseDeviceCode

For scheduled and unattended work, register an application, upload a certificate, grant application permissions with admin consent, and connect with no human in the loop:

Connect-MgGraph -TenantId <tenant-id> -ClientId <app-id> -CertificateThumbprint <thumbprint>

Get-MgContext shows who you are signed in as and which scopes were actually granted — run it first whenever a command returns a permissions error. Finish with Disconnect-MgGraph, particularly on shared jump boxes.

Old Cmdlet to New Cmdlet

Retired (AzureAD / MSOnline)Microsoft Graph PowerShell
Connect-AzureADConnect-MgGraph -Scopes ...
Get-AzureADUser -ObjectIdGet-MgUser -UserId
New-AzureADUserNew-MgUser
Set-AzureADUser -AccountEnabled $falseUpdate-MgUser -AccountEnabled:$false
Remove-AzureADUserRemove-MgUser
Get-AzureADGroupGet-MgGroup
Get-AzureADUserMembershipGet-MgUserMemberOf
Disconnect-AzureADDisconnect-MgGraph

Things That Trip People Up

Paging. Graph returns 100 objects per page by default. Get-MgUser on its own does not return your whole tenant — add -All. Forgetting this produces reports that quietly under-count.

Property selection. Many attributes are not returned unless you ask. If a property comes back empty when you know it has a value, add it to -Property and then select it in the pipeline.

Advanced queries. Filters on some properties require the ConsistencyLevel header and a count — the error message when you omit it is unhelpfully generic.

Scopes are cumulative per session. Connecting with a narrow scope set and then running a command needing more does not silently escalate; you must reconnect requesting the additional scope.

Delegated versus application permissions. An interactive session is limited by both the granted scope and your own role. A command that works for a Global Administrator interactively can still fail under a service principal that was granted only delegated consent.

Related Tools

If you administer the wider Microsoft stack, the same command-builder pattern is available for Exchange Online PowerShell, Windows Update PowerShell, and Group Policy commands. When a task involves setting a temporary password, generate it with the secure password generator rather than reusing a pattern across accounts.

Frequently Asked Questions

Is the AzureAD PowerShell module still supported?

No. The AzureAD and MSOnline modules were retired on 30 March 2025. Scripts built on them should be migrated to the Microsoft Graph PowerShell SDK. This tool shows legacy cmdlets only for reference, clearly labelled as deprecated, so you can map an old script to its replacement.

Which module do I install?

Run Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force. Verify with Get-InstalledModule Microsoft.Graph and keep it current with Update-Module Microsoft.Graph.

Why do I get “Insufficient privileges to complete the operation”?

The scopes granted to your session do not cover the call. Check what you actually have with Get-MgContext, then reconnect with the scopes this tool lists for that task. If you are using app-only auth, the application permission also needs admin consent in the tenant.

How do I connect without a browser?

Use device code flow: Connect-MgGraph -Scopes "User.Read.All" -UseDeviceCode. PowerShell prints a URL and a code that you enter from any other device. For fully unattended jobs, use certificate-based app-only authentication instead.

Can I find accounts with no MFA registered?

Yes — the MFA & Auth tab builds a command around Get-MgUserAuthenticationMethod that enumerates each user’s registered methods. Accounts whose only method is a password are the ones to chase.

Does the tool run commands against my tenant?

No. It generates text in your browser and never contacts Microsoft or any server of ours. Values you type stay on your machine. You run the copied command yourself, in your own session, so you keep full control over what executes.

Why does my report only show 100 users?

Graph pages results. Add -All to the cmdlet to retrieve every object rather than the first page.

Is Microsoft Entra ID the same as Azure AD?

Yes. Azure Active Directory was renamed Microsoft Entra ID; the directory, the objects and the Graph API are the same. The old name survives in search habits, documentation and countless scripts, which is why this page uses both.

What Is Azure AD PowerShell

Azure Active Directory (now Microsoft Entra ID) PowerShell modules enable administrators to manage identity, access, and directory services programmatically. Instead of clicking through the Azure portal for each user, group, or policy change, PowerShell commands allow bulk operations, automation, and scripted management of cloud identities at enterprise scale.

Two primary modules exist: the older MSOnline (MSOL) module and the newer Microsoft Graph PowerShell SDK. Microsoft is deprecating MSOL in favor of the Graph SDK, making it essential for administrators to understand both modules during the transition period.

Module Comparison

FeatureMSOnline (MSOL)AzureAD ModuleMicrosoft Graph PowerShell
StatusDeprecated (March 2024)DeprecatedCurrent / Recommended
AuthenticationBasic + MFABasic + MFAModern auth, certificate, managed identity
ScopeAzure AD onlyAzure AD onlyAll Microsoft 365 services
Command prefixMsol-AzureAD-Mg-
InstallInstall-Module MSOnlineInstall-Module AzureADInstall-Module Microsoft.Graph

Common Use Cases

  • Bulk user management: Create, modify, disable, or delete hundreds of user accounts using CSV imports and PowerShell loops
  • License assignment automation: Assign and remove Microsoft 365 licenses based on group membership, department, or custom attributes
  • Security policy enforcement: Configure Conditional Access policies, MFA settings, and password policies programmatically
  • Audit and compliance reporting: Extract sign-in logs, MFA registration status, guest user inventories, and privilege reports for auditors
  • Onboarding/offboarding automation: Script the complete onboarding (create account, assign licenses, add to groups, send welcome email) and offboarding (disable, remove licenses, transfer mailbox) workflows

Best Practices

  1. Migrate to Microsoft Graph PowerShell — MSOL and AzureAD modules are deprecated. Start migrating scripts to use the Microsoft.Graph SDK now to avoid breaking changes.
  2. Use certificate-based authentication for automation — Service principals with certificates are more secure than stored credentials for unattended scripts. Never hardcode passwords in scripts.
  3. Apply least-privilege permissions — When connecting to Microsoft Graph, request only the scopes your script needs. Avoid using broad permissions like Directory.ReadWrite.All when Directory.Read.All suffices.
  4. Test in a non-production tenant — Use an Azure AD development tenant for testing scripts before running them against production. Bulk operations cannot easily be undone.
  5. Log all administrative actions — Pipe script output to log files and enable Azure AD audit logs. Administrative changes should be traceable for compliance and incident investigation.

Frequently Asked Questions

Why use the Microsoft Graph PowerShell SDK instead of the AzureAD or MSOnline modules?+

The AzureAD and MSOnline modules were deprecated and retired by Microsoft on March 30, 2025. The Microsoft Graph PowerShell SDK is the supported replacement, built on the Microsoft Graph API, and receives all new features and security fixes. This builder generates Graph commands by default and only shows the old AzureAD/MSOnline equivalents as a secondary reference where they still function.

How do I install and connect to Microsoft Graph PowerShell?+

Install the SDK for your account with Install-Module Microsoft.Graph -Scope CurrentUser -Force (no admin rights needed). Then connect with Connect-MgGraph -Scopes "User.Read.All" (or whichever scopes your task needs). On a headless server use -UseDeviceCode, and for unattended automation use app-only auth with -ClientId and -CertificateThumbprint. Run Disconnect-MgGraph when finished.

What are scopes and why does the builder pick minimal ones?+

Scopes are the delegated permissions you grant to a Connect-MgGraph session. Requesting the minimum needed (for example User.Read.All for a read instead of Directory.ReadWrite.All) follows least-privilege and reduces risk if the session is compromised. This tool sets the smallest scope set for each task automatically and shows it above the generated script, along with the Entra role required to run it.

How do I check or report on a user's MFA status?+

Use Get-MgUserAuthenticationMethod -UserId user@contoso.com to list the authentication methods registered for a user. The builder's "List users without MFA registered" task loops every user and flags anyone whose only method is the password, and the "Per-user MFA method report" task builds a full export. Both need the UserAuthenticationMethod.Read.All scope.

How do I assign or remove a license with Microsoft Graph PowerShell?+

A usage location must be set first: Update-MgUser -UserId user@contoso.com -UsageLocation "US". Then resolve the SKU ID from its part number with Get-MgSubscribedSku and call Set-MgUserLicense -UserId user@contoso.com -AddLicenses @{ SkuId = $skuId } -RemoveLicenses @(). To remove, pass the SKU ID in -RemoveLicenses instead. The License Administrator role is required.

Why is SignInActivity / LastSignInDateTime empty in my reports?+

The SignInActivity property (used by the last sign-in and inactive-user reports) requires an Entra ID P1 or P2 license and the AuditLog.Read.All scope. Without both, the field returns null for every user. Connect with Connect-MgGraph -Scopes "AuditLog.Read.All","User.Read.All" and confirm the tenant has the right licensing.

How do I disable and offboard a user account?+

Block sign-in with Update-MgUser -UserId user@contoso.com -AccountEnabled:$false, then immediately revoke active tokens with Revoke-MgUserSignInSession -UserId user@contoso.com so existing sessions are signed out. The builder's "Disable an account" task generates both steps. Deleting a user (Remove-MgUser) is a soft delete; the account stays restorable for 30 days.

Can I export the reports to CSV?+

Yes. Reporting, licensing, group, MFA, and device tasks expose an optional CSV export path field. When you fill it in, the generated script pipes the results to Export-Csv -Path "C:\Reports\report.csv" -NoTypeInformation -Encoding UTF8 instead of formatting to the console, so you can open the output in Excel or hand it to compliance.

This tool is provided for informational and educational purposes only. All processing happens in your browser — no data is sent to or stored on our servers. While we strive for accuracy, we make no warranties about the completeness or reliability of results.