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.
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
https://learn.microsoft.com/en-us/graph/sdks/sdk-installationInstall stepshttps://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell-on-windows?view=powershell-7.6Install stepshttps://learn.microsoft.com/en-us/powershell/scripting/install/install-powershell-on-macos?view=powershell-7.6Install stepsAlso 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
11 steps
- 1
Check your PowerShell version
Where: Windows: Start menu > PowerShell 7 (or Windows PowerShell). Mac: Terminal, then type pwshMicrosoft 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.PSVersionYou should see: Major 7 for PowerShell 7, or Major 5 Minor 1 for Windows PowerShell. - 2
Install PowerShell 7 if you need it
Where: Windows Terminal on your admin PC, or a browser and Terminal on your MacWindows: 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
pwshin Terminal.winget install --id Microsoft.PowerShell --source wingetYou should see: Windows shows a PowerShell 7 item in the Start menu. On a Mac, pwsh opens a PS prompt. - 3
Set the execution policy
Where: PowerShell on your admin computerCheck the policy and, if it is stricter than RemoteSigned, set it for your user account.
Get-ExecutionPolicy Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUserYou should see: Get-ExecutionPolicy returns RemoteSigned (or a less restrictive value). - 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 -ForceYou should see: The prompt returns with no red error text. - 5
Confirm the install
Where: Same PowerShell windowCheck the installed version. It should match the latest version on the PowerShell Gallery.
Get-InstalledModule Microsoft.GraphYou should see: One line showing Version, Name Microsoft.Graph and Repository PSGallery. - 6
Find the scopes your command needs
Where: Same PowerShell windowAsk the SDK which permissions a cmdlet needs, then request only those.
Find-MgGraphCommand -command Get-MgUser | Select -First 1 -ExpandProperty PermissionsYou should see: A list of permission names such as User.Read.All and Directory.Read.All, with an IsAdmin column. - 7
Connect with the scopes you need
Where: Same PowerShell windowRun
Connect-MgGraphwith 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
Grant consent
Where: The browser sign-in window that Connect-MgGraph openedMicrosoft 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-MgGraphagain with the extra scopes.You should see: The browser says you can close the window, and PowerShell shows the welcome message. - 9
Use device code sign-in if the browser will not open
Where: PowerShell on a server, jump box or remote sessionUse 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 $trueYou should see: PowerShell shows a code and a URL; after you sign in elsewhere, the welcome message appears. - 10
Check who you are signed in as
Where: Same PowerShell windowShow the session details, then list every scope you have consented to, one per line.
Get-MgContext Get-MgContext | Select -ExpandProperty ScopesYou 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
Sign out when finished
Where: Same PowerShell windowYou stay signed in until you disconnect. Disconnect clears the cached token.
Disconnect-MgGraphYou should see: Get-MgContext returns nothing.
Expert tips
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.
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.
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.
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.
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.
How to confirm it worked
Get-InstalledModule Microsoft.Graphreturns a version from PSGallery.Get-MgContextshows your Account, TenantId and the Scopes you asked for.
How to reverse it
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 -AllVersionsGet-InstalledModule Microsoft.Graph.* | ? Name -ne "Microsoft.Graph.Authentication" | Uninstall-Module -AllVersionsUninstall-Module Microsoft.Graph.Authentication -AllVersions
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 nameCause: 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 connectingCause: 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.
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.
Official sources
Vendors change menus and requirements. Confirm on the source before you rely on a detail. Last checked 4 Nov 2026.