Get Connect-MsolService (and other Azure Active Directory PowerShell cmdlets) working (2023)

This post was last updated on October 4, 2022.

8 reading minute.

In this post, I will try to archive everything you need to download and install to use commands likeConnect-MsolServiceTo work. I had to do this a few times when switching laptops, so it's good to document them somewhere! :)

So when do you need to follow this guide and install the modules described here? Most of the time this comes into play when you switch computers, you try to run the SharePoint Online Management Shell but it doesn't even exist on the computer, or it exists but you get random errors like this:

The following guide should help you! I'll try to keep you updated as things change.

Depending on your use case, you may not always need all of these, but these are the ones I had to install recently (on Windows 10), so I'll document them :)

Now, to run cmdlets like Connect-MsolService, simply start the SharePoint Online Management Shell (or Windows PowerShell).

If using the modules still fails, you may be running PowerShell 64b but have the initial 32b cmdlets installed, or vice versa. In this case, you can simply start the correct version of PowerShell by looking for it in your directory structure. 32b can at least be started with imported MSOnline with the following commands:

You may need to use a specific version and architecture of PowerShell to run certain scripts because modules are installed separately between different versions. You can find more information here below:

These are the commands that should work. They are here for your future reference:

See all AzureActiveDirectory/MSOnline (v1) cmdlets by clicking this text.

AzureActiveDirectory-Cmdlets (v1)

Add MsolAdministrativeUnitMember

Adds a member to an administrative unit.

Add MsolForeignGroupToRole

Adds a security group from a tenant associated with a role in that tenant.

Add MsolGroupMember

Adds a member to an existing security group.

Add MsolRoleMember

Add a member to an administrator role.

Add MsolScopedRoleMember

Adds a member to a role at the administrative unit scope.


Verify a custom domain.


Confirm ownership of a non-managed tenant.


Starts a connection to Azure Active Directory.


Converts the domain from using basic authentication to using single sign-on.


Converts the domain from using single sign-on (also known as identity federation) to using basic authentication.


Upgrades a user in a domain that was recently converted from single sign-on.

Disable MsolDevice

Disables a device object in Azure Active Directory.


Activates a device object in Azure Active Directory.

Get MsolAccountSku

Returns all SKUs for a company.


Gets administrative units from Azure AD.


Gets the members of an administrative unit.

Get MsolAllSettings

Gets all directory configuration objects associated with the tenant or group/user/service principal/application/device.


Retrieves all directory configuration templates owned by a tenant.


Retrieve a company's current allowed data locations from Azure Active Directory.


Retrieves information at the company level.


Retrieves contacts from Azure Active Directory.


Retrieves the configuration of the Azure Active Directory device registration service.

Get MsolDevice

Gets a single device or a list of devices.


Gets the directory synchronization settings.


Gets the status of the identity synchronization functions for a tenant.


Searches for objects with synchronization provisioning failures in a tenant.

Get MsolDomain

Gets a domain from Microsoft Azure Active Directory.


Gets the key configuration for a federated domain.


Retrieves the DNS records needed to verify a domain.


Displays the server properties for Active Directory Federation Services 2.0 and Microsoft Online.


Gets a Microsoft Azure Active Directory group.


Gets all members of the specified group.



Gets a list of contracts for a partner.


Retrieves company-level information for partners.


Gets the current password policy for a tenant or domain.

Get MsolRole

Gets administrator roles.

Get MsolRoleMember

Gets the members of a role.


Gets the members of a role who have been granted that role through an administrative entity.


Gets a service principal or a list of service principals from Microsoft Azure Active Directory.


Gets the credentials associated with a service principal.


Gets a directory configuration.


Gets a directory configuration template.


You get subscriptions.


Retrieves users from Azure Active Directory.


Gets users based on a strong authentication type.

Get MsolUserRole

Gets a list of roles to which the specified user belongs.


Adds a new administrative unit to Azure Active Directory.


Add a domain to Azure Active Directory.


Adds a new SSO domain to Microsoft Online Services and establishes the relying party trust.


Add a new group to Azure Active Directory.


Creates a license option object.


Add a service principal to Azure Active Directory.


Create a primary service address.


Add a credential key to a service principal.

New Msol configuration

Create a directory configuration.


Create a user in Azure Active Directory.


Create a known group.


Reprovision a contact object in Azure Active Directory.


Repeat provisioning of a group object in Azure Active Directory.


Repeat provisioning of a user object in Azure Active Directory.


Deletes an administrative unit from Azure Active Directory.


Removes a member from an administrative unit.


Remove a password for an app.


Delete a contact from Azure Active Directory.

Remove MsolDevice

Remove a device object from Azure Active Directory.

Remove MsolDomain

Removes a domain from Azure Active Directory.

Remove MsolFederatedDomain

Removes an SSO domain from domains in Microsoft Online.

Quitar MsolForeignGroupFromRole

Removes a security group from an associated tenant.

Remove MsolGroup

Removes a group from Azure Active Directory.

Remove MsolGroupMember

Removes a member from a security group.

Remove MsolRoleMember

Remove a member from an admin role.

Remove MsolScopedRoleMember

Removes a user from a role at the administrative unit scope.

Remove MsolServicePrincipal

Removes a service principal from Azure Active Directory.


Removes a credential key from a service principal.

Remove MsolSettings

Deletes a directory configuration.


Deletes a user from Microsoft Azure Active Directory.

Reset MsolStrongAuthenticationMethodByUpn

Resets the strong authentication method using a user principal name.


Restores a deleted user.

Set MsolADFSContext

Sets the context and credentials to connect to Microsoft Online and the Active Directory Federation Services 2.0 server.


Updates the properties of an administrative entity.


Sets an allowed data location for a service type for an organization in Azure Active Directory.


Establishes contact information at the company level.


Enables multinational capability for a service type for a company using Azure Active Directory.


No online service uses this cmdlet, so consider it deprecated.

Set contact preferences for enterprise-level security and compliance.

Set MsolCompanySettings

Sets business-level configuration settings.


Configures the Azure Active Directory device registration service settings.


Change directory synchronization settings.


Turn directory synchronization on or off for a company.

Set MsolDirSyncFeature

Sets identity synchronization capabilities for a tenant.


Change the settings of a domain.


Change the authentication type of the domain.


Updates the configuration of a federated domain.


Updates a security group.


Sets the company information for partners.

Set MsolPasswordPolicy

Updates the password policy for a specified domain or tenant.


Updates a service principal in Microsoft Azure Active Directory.


Updates a directory configuration in Azure Active Directory.


Modifies a user in Azure Active Directory.


Updates the license assignment for a user.


Resets a user's password.


Changes the user ID of a user.


Updates the configuration on both the Active Directory Federation Services 2.0 server and Microsoft Online.

Azure AD v2 cmdlets in detail


Add an existing Office 365 user or Office 365 security group to a SharePoint group.


Connects a SharePoint Online global administrator to a SharePoint Online connection (the SharePoint Online admin center). This cmdlet must be run before any other SharePoint Online cmdlets can be run.


You are disconnected from a SharePoint Online service.


Returns application errors.

Get SPOAppInfo

Returns all installed applications.


Returns all deleted site collections that are in the recycle bin.


Returns the external users located in the tenant's folder based on the specified criteria.

Get SPOSite

Returns one or more site collections.


Returns all groups in the specified site collection.


Returns the SharePoint Online organization properties.

Get SPOTenantLogEntry

Retrieves company records from SharePoint Online.


Returns the time that the SharePoint Online organization logs were collected.


Returns the current configuration state of the tenant.


Returns the SharePoint Online user or security group accounts that match the specified search criteria.

Get SPOWebTemplate

Lists all site templates that match the specified identity.


Creates a new SharePoint Online site collection for the current company.


Creates a new group in a SharePoint Online site collection.


Removes a deleted SharePoint Online site collection from the recycle bin.


Permanently deletes a collection of external users from the tenants folder.

Pay SPOSite

Sends a SharePoint Online site collection to the SharePoint Online Recycle Bin.

Pay off SPOSiteGroup

Removes a SharePoint Online group from a site collection.

Quitar SPOTenantSyncClientRestriction

Disables the feature for the tenant.


Removes a user or security group from a site collection or group.


Checks and repairs the specified site collection and its contents.


Requirements to create a copy of an existing site collection in order to verify the impact of the update without affecting the original site.


Restores a deleted SharePoint Online site collection from the recycle bin.


Sets or updates the values ​​of one or more properties for a site collection.


Updates the SharePoint Online owner and permission level of a group within a site collection.


Sets properties for the SharePoint Online organization.

Establecer SPOTenantSyncClientRestriction

Activates the tenant and sets the domain GUIDs.


Set properties for an existing user.


Test a SharePoint Online site collection.


Starts the upgrade process for a site collection.


What is the PowerShell cmdlet to connect to Azure AD? ›

To connect to the Azure Active Directory Module for Windows PowerShell or MSOnline module, use the Connect-MsolService cmdlet and supply the $M365credentials variable.

What commands can you use to find Windows PowerShell cmdlets for managing Active Directory groups? ›

Use the cmdlet Get-Command -Module ActiveDirectory to display all the cmdlets that can be used to manage Active Directory. The Get-Module -ListAvailable command displays all the modules. This allows you to see the names of other modules and use Get-Command to get their cmdlets (Figure 4).

How do I install MSOnline PowerShell module for Azure Active Directory? ›

Open an elevated Windows PowerShell command prompt (run Windows PowerShell as an administrator). Run the Install-Module MSOnline command. If you're prompted to install the NuGet provider, type Y and press Enter. If you're prompted to install the module from PSGallery, type Y and press Enter.

Why is connect MsolService not working? ›

What does this Connect-MsolService error mean? This error means that you do not have the Connect-MSonline module loaded within your PowerShell session or the module is not installed. If you have installed the module in the past, it may be corrupt and require re-installation.

How do I use cmdlet in PowerShell? ›

Steps to write a cmdlet
  1. To declare the class as a cmdlet, use the Cmdlet attribute. ...
  2. Specify the name of the class.
  3. Specify that the cmdlet derives from either of the following classes: ...
  4. To define the parameters for the cmdlet, use the Parameter attribute. ...
  5. Override the input processing method that processes the input.
17 Sept 2021

How do I connect to AD domain in PowerShell? ›

Connecting to the AD drive

Type Import-Module ActiveDirectory in the PowerShell window and press Enter. Now we need to set the working location to the AD drive. Type Set-Location AD: and press Enter. Notice that the PowerShell prompt now changes to PS AD: >.

How do I know if I am connected to Azure AD PowerShell? ›

Simply run any cmdlet related to the module. I use Get-AzureADTenantDetail cmdlet to set a variable representing the tenant name, and check for its existence.

How do I get a list of cmdlets in PowerShell? ›

Use CommandType or its alias, Type. By default, Get-Command gets all cmdlets, functions, and aliases. The acceptable values for this parameter are: Alias : Gets the aliases of all PowerShell commands.

How do I open Active Directory users and Computers using PowerShell? ›

Which would start a new cmd window running under the <admin account> credentials. From there, you could type dsa. msc to start Active Directory running as that <admin account> instead of the account you were logged in as.

What is the PowerShell command to list all cmdlets? ›

The PowerShell Get-Command cmdlet is used to get all the commands which are installed on the computer system. This cmdlet includes functions, other cmdlets, aliases, filters, scripts, and applications. We can get only those commands which have been imported into the current session by using the -ListImported parameter.

How do I run a PowerShell script from Azure CLI? ›

Run Command in Azure CLI

Open a Bash terminal. Log in to your Azure tenant using the az login command. If necessary, select a default subscription using the az account set command. Use the az vm run-command invoke and specify the --resource-group and --name of the virtual machine.

How do I connect Active Directory to Azure Active Directory? ›

Connect your organization to Azure AD
  1. Select. ...
  2. Select Azure Active Directory, and then select Connect directory.
  3. Select a directory from the dropdown menu, and then select Connect. ...
  4. Select Sign out. ...
  5. Confirm that the process is complete.
4 Oct 2022

Is Azure CLI same as PowerShell? ›

Azure CLI, Azure PowerShell, and Azure Cloud Shell have overlapping functionality. Each operates differently, and the language is sometimes confused with the environment.

Which PowerShell module must be loaded to run get MSOLUser? ›

The Get-MSOLUser command is part of the MSOnline PowerShell module.

Which PowerShell cmdlet can be used to install Active Directory Certificate Services? ›

The Install-AdcsCertificationAuthority cmdlet performs installation and configuration of the Active Directory Certificate Services (AD CS) Certification Authority (CA) role service.

How do I set up an intune connector in Active Directory? ›

Select Sign In. Enter the Global administrator or Intune administrator role credentials. The user account must have an assigned Intune license. Go to Devices > Windows > Windows enrollment > Intune Connector for Active Directory, and then confirm that the connection status is Active.

How do you check if ad Connect is working? ›

First, log in to the portal. Then, go to Azure Active Directory —> Azure AD Connect. Under the Azure AD Connect sync section, you should see the current status of the directory sync.

How do I connect to MS teams in PowerShell? ›

To connect to Microsoft Teams using PowerShell, you will need to first install the Microsoft Teams PowerShell module. This module can be installed from the PowerShell Gallery by running the following command: Install-Module -Name MicrosoftTeams.

What is the get MsolUser? ›

The Get-MsolUser cmdlet gets an individual user or list of users. Specify the ObjectId or UserPrincipalName parameter to get a specific user.

How do I add cmdlets to PowerShell? ›

How to load cmdlets using a module
  1. Create a module folder that has the same name as the assembly file in which the cmdlets are implemented. ...
  2. Make sure that the PSModulePath environment variable includes the path to your new module folder. ...
  3. Copy the cmdlet assembly into the module folder.
  4. Add a module manifest file ( .
17 Sept 2021

Is a cmdlet a command? ›

A cmdlet is a single command that participates in the pipeline semantics of PowerShell. This includes binary (C#) cmdlets, advanced script functions, CDXML, and Workflows.

What is cmdlet example? ›

Cmdlets are lightweight commands used in the PowerShell environment. Most of the cmdlets in PowerShell use the Verb-Noun format. For example, Get-Command, Update-Help, Start-Service, etc.

How do I run an Active Directory command in PowerShell? ›

Type Start PowerShell and press Enter within the Command Prompt window to open a new Windows PowerShell console window. Type Add-WindowsFeature AD-Domain-Services and press Enter to install Active Directory Domain Services.

How do I query Active Directory in PowerShell? ›

If the Active Directory Management module is installed in Windows 10/11 or Windows Server 2019/2022, you can also access specific Active Directory (AD) information in PowerShell. The "Get-Command Get-Ad*" command already shows numerous cmdlets that can display information from Active Directory.

How do I check if a domain is connected to PowerShell? ›

first command check if a computer is on domain using Get-WmiObject cmdlet. PartofDomain property of given cmdlet is Boolean type and return true or false based on computer domain membership. If computer is on domain, it will returns true else false. Second command, check if computer is on workgroup or not.

Which command should I use to connect to Azure PowerShell? ›

To sign in interactively, use the Connect-AzAccount cmdlet. This cmdlet presents an interactive browser based login prompt by default. Use the Get-AzContext cmdlet to store your tenant ID in a variable to be used in the next two sections of this article.

Which PowerShell cmdlet authenticates to an Azure account? ›

Description. The Connect-AzAccount cmdlet connects to Azure with an authenticated account for use with cmdlets from the Az PowerShell modules. You can use this authenticated account only with Azure Resource Manager requests.

What is the cmdlet to get the list of services? ›

The Get-Service cmdlet gets all the services on the computer and sends the objects down the pipeline.

Can PowerShell run cmdlets? ›

PowerShell lets administrators perform administrative tasks on both local and remote Windows systems. Those tasks are performed by using PowerShell cmdlets (command-lets), which are special simple commands, consist of two words — a verb and a noun — executing a simple function.

What is the PowerShell format for cmdlets? ›

Utility) - PowerShell. The Format-List cmdlet formats the output of a command as a list of properties in which each property is displayed on a separate line. You can use Format-List to format and display all or selected properties of an object as a list (Format-List -Property *).

Which parameter is used to get all Active Directory users on a PowerShell cmdlet? ›

Description. The Get-ADUser cmdlet gets a specified user object or performs a search to get multiple user objects. The Identity parameter specifies the Active Directory user to get.

What PowerShell cmdlet can be used to add an Active Directory user? ›

The New-ADUser cmdlet creates an Active Directory user. You can set commonly used user property values by using the cmdlet parameters.

How do I run Active Directory users and computers as a different user? ›

How do I login as a different user when Active Directory SSO is enabled?
  1. Hold 'Shift' and right-click on your browser icon on the Desktop/Windows Start Menu.
  2. Select 'Run as different user'.
  3. Enter the login credentials of the user you wish to use.
15 Jun 2018

How many cmdlets are in PowerShell? ›

Over 200 cmdlets can be used in PowerShell.

How do I run an Azure command-line script? ›

Subsequent sessions will use Azure CLI in a Bash environment, Select Copy to copy the blocks of code, paste it into the Cloud Shell, and press Enter to run it.

How do I connect to Azure command-line? ›

How to sign into the Azure CLI. Before using any Azure CLI commands with a local install, you need to sign in with az login. Run the login command. If the CLI can open your default browser, it will initiate authorization code flow and open the default browser to load an Azure sign-in page.

How do I check Azure AD Connect settings? ›

  1. Sign into the AAD Sync Server with a local admin account that is also part of the SyncAdmins group.
  2. Open the Azure AD Connect Wizard.
  3. Click "Configure" on the Welcome screen.
  4. Select "View Current Configuration"
  5. View the configurations.
28 Apr 2021

How do I run Active Directory from command prompt? ›

How to search Active Directory
  1. Click Start, and then click Run.
  2. In the Open box, type cmd.
  3. At the command prompt, type the command dsquery user parameter . The parameter specifies the parameter to use. For the list of parameters, see the online help for the d squery user command.
24 Sept 2021

How do I force sync between Azure and AD? ›

Use the following steps to force a remote synchronization of AD and Azure: Use the Enter-PSSession command to connect to your Azure AD Connect server. Perform a delta synchronization using the Start-ADSyncSyncCycle command. Exit the PSSession to kill the connection to your Azure AD Connect server.

Can I use PowerShell instead of command prompt? ›

For those who prefer using Command Prompt, you can opt out of the Windows Logo Key + X change by opening Settings > Personalization > Taskbar, and turning off, Replace Command Prompt with Windows PowerShell in the menu when I right-click the start button or press Windows key+X.

How do I install Azure CLI in Windows using PowerShell? ›

Install Azure CLI 2.0 on Microsoft Windows
  1. Download the Azure CLI 2.0 MSI installer here.
  2. Launch the installer, select the check box to accept the License Agreement terms, and then click Install.
  3. From a command line (Windows Command Prompt or PowerShell), run the az login command.

Which is better PowerShell or command prompt? ›

The most notable advantage of using PowerShell over the command prompt is PowerShell's extensibility. While you can create tools for both by writing scripts, the command prompt is limited as an interpreter.

How do I connect SQL Server management Studio to PowerShell? ›

Use Win + R , on your Windows computer, and type PowerShell to launch a new Windows PowerShell session. SQL Server provides a PowerShell module named SqlServer. You can use the SqlServer module to import the SQL Server components (SQL Server provider and cmdlets) into a PowerShell environment or script.

How does Office 365 tenant connect to PowerShell? ›

Connecting to Office 365(Exchange Online) via Powershell
  1. Open Powershell as administrator.
  2. Run command – Set-ExecutionPolicy Remotesigned.
  3. Type Y for yes.
  4. Run command – $UserCredential = Get-Credential.
  5. Sign in with O365 administrator account (
  6. Run command – Import-PSSession $Session.

How does AKS cluster connect to PowerShell? ›

Connect to the cluster
  1. Install kubectl locally using the Install-AzAksKubectl cmdlet: Azure PowerShell Copy. ...
  2. Configure kubectl to connect to your Kubernetes cluster using the Import-AzAksCredential cmdlet. ...
  3. Verify the connection to your cluster using the kubectl get command.
1 Nov 2022

How do I load SMO assembly into SQL PowerShell? ›

Loading SMO assemblies
  1. Open up your PowerShell console, PowerShell ISE, or your favorite PowerShell Editor.
  2. Type the import-module command as follows: Import-Module SQLPS Copy.
  3. Confirm that the module is loaded by running the following. This should give the name of the module if it is loaded: Get-Module Copy.

Can we run PowerShell script in SQL query? ›

Run PowerShell from SQL Server Agent

You can code Windows PowerShell scripts, and then use SQL Server Agent to include the scripts in jobs that run at scheduled times or in response to SQL Server events. Windows PowerShell scripts can be run using either a command prompt job step or a PowerShell job step.

How do I run a PowerShell script from the SQL Server Agent job? ›

In the New Job Step dialog, type a job Step name. In the Type list, select PowerShell. In the Run as list, select the proxy account with the credentials that the job will use. In the Command box, enter the PowerShell script syntax that will be executed for the job step.

How do I get MSOnline module? ›

To install the MSOnline module, launch PowerShell 64 bit in administrative mode and run the following command:
  1. Install-Module MSOnline. ...
  2. Install-PackageProvider NuGet. ...
  3. $currentPrincipal = New-Object Security. ...
  4. Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope Process.
2 May 2020

Which PowerShell cmdlet shows Azure AD tenant information? ›

The Get-AzureADTenantDetail cmdlet gets the details of a tenant in Azure Active Directory (AD).

How do I access AKS cluster from command line? ›

Connect to AKS Cluster from your laptop/workstation
  1. Install AZ CLI. Ensure you have installed az cli. ...
  2. Install Kubectl. There are two ways: AZ CLI or manually installing kubectl.exe. ...
  3. Connect to AKS Cluster. Similar to cloud shell method, just run az aks get-credentials command to connect to your cluster.
25 Jun 2021

Which command connects to an AKS cluster? ›

Connect to the cluster

To manage a Kubernetes cluster, use the Kubernetes command-line client, kubectl. kubectl is already installed if you use Azure Cloud Shell. Configure kubectl to connect to your Kubernetes cluster using the az aks get-credentials command.

How do I connect two AKS clusters? ›

Managing multiple AKS clusters from CLI:

Once you setup another AKS cluster use az aks list -o table command and get the list of clusters. Get the credentials to the new cluster by using the az aks get-credentials command. Now, you can use kubectl config get-contexts to see all AKS clusters you are authenticated to.

How do I install MS Teams module in PowerShell? ›

Follow these steps to install the module:
  1. Update to Windows PowerShell 5.1. If you're on Windows 10 version 1607 or higher, you already have PowerShell 5.1 installed.
  2. Install . NET Framework 4.7. ...
  3. Run the following command to install the latest PowerShellGet: PowerShell Copy. ...
  4. Install the Teams PowerShell Module.
25 May 2022

What is the cmdlet to connect to Microsoft Teams using Windows PowerShell? ›

The Connect-MicrosoftTeams cmdlet connects to Microsoft Teams with an authenticated account for use with cmdlets from the MicrosoftTeams PowerShell module. After executing this cmdlet, you can disconnect from MicrosoftTeams account using Disconnect-MicrosoftTeams. Note: With versions 4.

How do I run a PowerShell team command? ›

Getting Started with PowerShell to Manage Microsoft Teams
  1. Install the Teams PowerShell module. Launch a PowerShell window and use the following command: PS> Install-Module -Name MicrosoftTeams. ...
  2. Sign in. ...
  3. List the available cmdlets.
5 Jun 2020


Top Articles
Latest Posts
Article information

Author: Dong Thiel

Last Updated: 12/09/2023

Views: 6237

Rating: 4.9 / 5 (59 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Dong Thiel

Birthday: 2001-07-14

Address: 2865 Kasha Unions, West Corrinne, AK 05708-1071

Phone: +3512198379449

Job: Design Planner

Hobby: Graffiti, Foreign language learning, Gambling, Metalworking, Rowing, Sculling, Sewing

Introduction: My name is Dong Thiel, I am a brainy, happy, tasty, lively, splendid, talented, cooperative person who loves writing and wants to share my knowledge and understanding with you.