How-to · Microsoft 365 admin

Install Microsoft Graph PowerShell and connect

At the end you will have the Microsoft Graph PowerShell SDK installed, be signed in with only the permission scopes you need, and know how to check and close the session.

Updated 4 Nov 202611 steps6 official sources
Before you start

What you need before step 1

Applies to: Microsoft Graph PowerShell SDK (Microsoft.Graph and Microsoft.Graph.Beta modules) on PowerShell 7 for Windows and macOS, and Windows PowerShell 5.1, as documented by Microsoft

Admin roles you need

  • Any Microsoft Entra user can sign in, but the scopes you request decide what you can do
  • Application Administrator or Cloud Application Administrator (or Global Administrator) to grant consent to scopes that need admin consent
  • Plus the directory role the task itself needs, for example User Administrator to change users

Licences

None needed.

Install instructions

Microsoft Graph PowerShell SDK (installed from the PowerShell Gallery)Microsoft's install page; the Install-Module command in step 4 downloads ithttps://learn.microsoft.com/en-us/graph/sdks/sdk-installationInstall steps
PowerShell 7 for WindowsRecommended by Microsoft for the SDKhttps://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell-on-windows?view=powershell-7.6Install steps
PowerShell 7 for macOS (.pkg)Required on a Machttps://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell-on-macos?view=powershell-7.6Install steps

Also have ready

  • If you stay on Windows PowerShell, Microsoft requires version 5.1 or later, .NET Framework 4.7.2 or later and an updated PowerShellGet
  • Execution policy RemoteSigned or less restrictive
Step by step

11 steps

  1. 1

    Check your PowerShell version

    Where: Windows: Start menu > PowerShell 7 (or Windows PowerShell). Mac: Terminal, then type pwsh

    Microsoft recommends PowerShell 7 or later on all platforms because it needs no extra prerequisites. An install only applies to the PowerShell version you ran it in.

    $PSVersionTable.PSVersion
    You should see: Major 7 for PowerShell 7, or Major 5 Minor 1 for Windows PowerShell.
  2. 2

    Install PowerShell 7 if you need it

    Where: Windows Terminal on your admin PC, or a browser and Terminal on your Mac

    Windows: run the winget command below, or download the MSI from Microsoft's install page. macOS: download the .pkg for your processor from Microsoft's macOS install page, double-click it, then type pwsh in Terminal.

    winget install --id Microsoft.PowerShell --source winget
    You should see: Windows shows a PowerShell 7 item in the Start menu. On a Mac, pwsh opens a PS prompt.
  3. 3

    Set the execution policy

    Where: PowerShell on your admin computer

    Check the policy and, if it is stricter than RemoteSigned, set it for your user account.

    Get-ExecutionPolicy
    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
    You should see: Get-ExecutionPolicy returns RemoteSigned (or a less restrictive value).
  4. 4

    Install the Microsoft.Graph module

    Where: Same PowerShell window (run as administrator only if you choose AllUsers)

    Install for your account. The module pulls in dozens of submodules, so allow a few minutes. Use the AllUsers line instead if everyone on the computer needs it. Install Microsoft.Graph.Beta only if a task needs beta endpoints; Microsoft recommends v1.0 for scripts.

    Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force
    Install-Module Microsoft.Graph -Scope AllUsers -Repository PSGallery -Force
    Install-Module Microsoft.Graph.Beta -Repository PSGallery -Force
    You should see: The prompt returns with no red error text.
  5. 5

    Confirm the install

    Where: Same PowerShell window

    Check the installed version. It should match the latest version on the PowerShell Gallery.

    Get-InstalledModule Microsoft.Graph
    You should see: One line showing Version, Name Microsoft.Graph and Repository PSGallery.
  6. 6

    Find the scopes your command needs

    Where: Same PowerShell window

    Ask the SDK which permissions a cmdlet needs, then request only those.

    Find-MgGraphCommand -command Get-MgUser | Select -First 1 -ExpandProperty Permissions
    You should see: A list of permission names such as User.Read.All and Directory.Read.All, with an IsAdmin column.
  7. 7

    Connect with the scopes you need

    Where: Same PowerShell window

    Run Connect-MgGraph with a comma-separated list of scopes. A sign-in page opens. Sign in with your admin account.

    Connect-MgGraph -Scopes "User.Read.All","Group.ReadWrite.All"
    You should see: After sign-in PowerShell shows Welcome to Microsoft Graph!
  8. 8

    Grant consent

    Where: The browser sign-in window that Connect-MgGraph opened

    Microsoft Graph PowerShell permissions are not pre-authorised, so the first time you request a scope a permissions request appears. Review the list and accept. Scopes that need admin consent must be accepted by an account with Application Administrator or Cloud Application Administrator. To add more scopes later, run Connect-MgGraph again with the extra scopes.

    You should see: The browser says you can close the window, and PowerShell shows the welcome message.
  9. 9

    Use device code sign-in if the browser will not open

    Where: PowerShell on a server, jump box or remote session

    Use device code flow and complete sign-in on another device. If the sign-in pop-up hangs on Windows, turn off Web Account Manager sign-in and try again.

    Connect-MgGraph -Scopes "User.Read.All","Group.ReadWrite.All" -UseDeviceAuthentication
    Set-MgGraphOption -DisableLoginByWAM $true
    You should see: PowerShell shows a code and a URL; after you sign in elsewhere, the welcome message appears.
  10. 10

    Check who you are signed in as

    Where: Same PowerShell window

    Show the session details, then list every scope you have consented to, one per line.

    Get-MgContext
    Get-MgContext | Select -ExpandProperty Scopes
    You should see: Account shows your admin UPN, TenantId shows your tenant GUID, AuthType shows Delegated and AppName shows Microsoft Graph PowerShell. The second command lists scopes such as User.Read.All.
  11. 11

    Sign out when finished

    Where: Same PowerShell window

    You stay signed in until you disconnect. Disconnect clears the cached token.

    Disconnect-MgGraph
    You should see: Get-MgContext returns nothing.
From experience

Expert tips

Install only the submodules you need

The full Microsoft.Graph module pulls in dozens of submodules and takes minutes to install and load. For migration scripts, install just what you use, for example Install-Module Microsoft.Graph.Users, Microsoft.Graph.Identity.DirectoryManagement -Scope CurrentUser. Microsoft.Graph.Authentication comes with them.

Confirm the tenant before every change

In tenant-to-tenant work it is easy to run a script in the wrong tenant. Connect with Connect-MgGraph -TenantId <tenant ID> -Scopes ... and check Get-MgContext shows the expected TenantId and Account before any create, update or delete. Disconnect before switching tenants.

Request the fewest scopes

Use Find-MgGraphCommand to see which permissions a cmdlet needs and ask only for those. Read-only reporting rarely needs ReadWrite scopes. Scopes that need admin consent must be approved once by an Application Administrator or Cloud Application Administrator; reconnect with the extra scope when you need more.

Use -All on list cmdlets

Get-Mg list cmdlets return only the first page of results unless you add -All. A user or group report without it looks complete but quietly stops early, which is a nasty surprise in a pre-migration inventory.

Fix sign-in hangs with device code or WAM off

On jump boxes and remote sessions where the sign-in window hangs, use -UseDeviceAuthentication, or turn off Web Account Manager with Set-MgGraphOption -DisableLoginByWAM $true and try again.

Check it worked

How to confirm it worked

  • Get-InstalledModule Microsoft.Graph returns a version from PSGallery.

  • Get-MgContext shows your Account, TenantId and the Scopes you asked for.

Undo

How to reverse it

Rollback:

Run Disconnect-MgGraph to sign out. To remove the SDK, uninstall the main module first, then the submodules, leaving Microsoft.Graph.Authentication until last:

Uninstall-Module Microsoft.Graph -AllVersions
Get-InstalledModule Microsoft.Graph.* | ? Name -ne "Microsoft.Graph.Authentication" | Uninstall-Module -AllVersions
Uninstall-Module Microsoft.Graph.Authentication -AllVersions

Troubleshooting

Errors you might see

Files cannot be loaded because running scripts is disabled on this system.

Cause: Execution policy is stricter than RemoteSigned.

Fix: Run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser and reopen PowerShell.

No match was found for the specified search criteria and module name

Cause: PSGallery is not registered as a repository on this computer.

Fix: Run Register-PSRepository -Default, then rerun Install-Module with -Repository PSGallery.

Authentication pop-up hangs or times out when connecting

Cause: Web Account Manager (WAM) broker sign-in does not work in that environment, for example on a jump box.

Fix: Run Set-MgGraphOption -DisableLoginByWAM $true, or use -UseDeviceAuthentication.

FAQ

Questions

Do I install Microsoft.Graph or Microsoft.Graph.Beta?

Install Microsoft.Graph for v1.0 endpoints. Microsoft.Graph.Beta is separate, can be installed alongside it and calls beta endpoints that can change without notice.

Why does Connect-MgGraph ask for consent?

Microsoft Graph PowerShell permissions are not pre-authorised, so each scope must be consented to once. Some scopes need an Application Administrator or Cloud Application Administrator to consent.

How do I update the SDK?

Run Update-Module Microsoft.Graph.

Can I install only the parts I need?

Yes. Microsoft says you can install individual submodules (Find-Module Microsoft.Graph* lists them); Microsoft.Graph.Authentication is installed with them.

Sources

Official sources

Vendors change menus and requirements. Confirm on the source before you rely on a detail. Last checked 4 Nov 2026.