Connect-MsolService no longer works. It belonged to the MSOnline PowerShell module, and Microsoft retired that module in 2025.
The replacement is Connect-MgGraph from the Microsoft Graph PowerShell SDK. Install it and sign in:
Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force
Connect-MgGraph -Scopes "User.Read.All"
Get-MgUser -Top 10
What happened to Connect-MsolService?
Connect-MsolService opened a session to Microsoft Entra ID (formerly Azure Active Directory) through the MSOnline module. Every other Msol cmdlet, such as Get-MsolUser or Set-MsolUserLicense, needed that session first.
Microsoft deprecated the MSOnline and Azure AD PowerShell modules on March 30, 2024. According to the Microsoft Entra release notes, MSOnline PowerShell retired and stopped working between early April 2025 and late May 2025.
Microsoft points MSOnline users to two replacements:
- Microsoft Graph PowerShell SDK. Connect-MgGraph is the direct equivalent of Connect-MsolService in the Microsoft cmdlet map.
- Microsoft Entra PowerShell. This module builds on the Graph SDK. Microsoft says it has over 80% parity with MSOnline cmdlets.
Why do I get "Connect-MsolService is not recognized"?
PowerShell shows this error when it can't find the cmdlet, usually because MSOnline isn't installed. Installing or importing MSOnline today doesn't help, because the module stopped working when it retired.
Switch the script to Connect-MgGraph instead. For more on the error, see the not recognized guide.
How do I connect with Connect-MgGraph?
Step 1: Check the prerequisites
Microsoft recommends PowerShell 7 or later for the Graph SDK. It also runs on Windows PowerShell 5.1 with these extras:
- .NET Framework 4.7.2 or later
- An up-to-date PowerShellGet module
- An execution policy of RemoteSigned or less restrictive
Set the execution policy for your account if needed:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Step 2: Install the Microsoft Graph module
Run this in the PowerShell version you plan to use:
Install-Module Microsoft.Graph -Scope CurrentUser -Repository PSGallery -Force
The Microsoft.Graph module installs over 47 submodules. Install only the submodules you need if you want a smaller footprint. Microsoft.Graph.Authentication holds Connect-MgGraph.
Check the installed version:
Get-InstalledModule Microsoft.Graph
For updates and removal, see the installation guide.
Step 3: Sign in with the scopes you need
Graph PowerShell permissions aren't pre-authorized, so you request scopes when you sign in.
Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All"
Sign in when prompted. Approve the requested permissions the first time you use them.
Add -TenantId to sign in to a specific tenant:
Connect-MgGraph -Scopes "User.Read.All" -TenantId "contoso.onmicrosoft.com"
Step 4: Check the session
Run Get-MgContext to see the account, tenant and scopes for the current session:
Get-MgContext
The SDK caches your token and refreshes it for you. You stay signed in across PowerShell sessions until you sign out:
Disconnect-MgGraph
How do I connect without a user sign-in?
Scripts that run with no one signed in use app-only access. This needs an app registration in Microsoft Entra ID with a certificate.
Connect-MgGraph -ClientId "00001111-aaaa-2222-bbbb-3333cccc4444" -TenantId "contoso.onmicrosoft.com" -CertificateThumbprint "AA11BB22CC33DD44EE55FF66AA77BB88CC99DD00"
The certificate must be in Cert:\CurrentUser\My or Cert:\LocalMachine\My. Connect-MgGraph also accepts a client secret credential or a managed identity. For every option, see the authentication cmdlets guide.
Which Graph cmdlets replace the Msol cmdlets?
Old scripts won't run as they are. Cmdlet names, parameters and output objects all changed. Start with the cmdlet names:
| MSOnline cmdlet | Microsoft Graph PowerShell cmdlet |
|---|---|
| Connect-MsolService | Connect-MgGraph |
| Get-MsolUser | Get-MgUser |
| New-MsolUser | New-MgUser |
| Set-MsolUser | Update-MgUser |
| Remove-MsolUser | Remove-MgUser |
| Set-MsolUserLicense | Set-MgUserLicense |
| Set-MsolUserPassword | Reset-MgUserAuthenticationMethodPassword |
| Get-MsolAccountSku | Get-MgSubscribedSku |
| Get-MsolGroup | Get-MgGroup |
| Get-MsolGroupMember | Get-MgGroupMember |
| Get-MsolRole | Get-MgDirectoryRole |
| Get-MsolRoleMember | Get-MgDirectoryRoleMember |
| Get-MsolDomain | Get-MgDomain |
| Get-MsolCompanyInformation | Get-MgOrganization |
| Get-MsolDevice | Get-MgDevice |
For the rest, see the full cmdlet map.
Find the scopes a cmdlet needs with Find-MgGraphCommand:
Find-MgGraphCommand -Command 'Get-MgUser'
The output lists the API path and the permissions for the cmdlet. Pass those permissions to -Scopes when you connect.
What does a migrated command look like?
This counts the users whose display name starts with "a":
Connect-MgGraph -Scopes "User.Read.All"
Get-MgUser -ConsistencyLevel eventual -Count userCount -Filter "startsWith(DisplayName, 'a')" -Top 1
The -ConsistencyLevel eventual parameter turns on advanced queries such as -Count and -Search. Use -Search with -ConsistencyLevel eventual where old scripts used -SearchString.
In its migration guide, Microsoft suggests you document each old script first. Upgrade the simplest scripts first and test them before the critical ones.
For common Graph replacements, see: