Fix “Connect-AzureAD : The term ‘Connect-AzureAD’ is not recognized as the name of a cmdlet, function, script file, or operable program.” Error

Problem: When trying to connect to Azure AD from PowerShell using the “Connect-AzureAD” cmdlet, I received the error “Connect-AzureAD: The term ‘Connect-AzureAD’ is not recognized as the name of a cmdlet, function, script file, or operable program.”

Connect-AzureAD The term Connect-AzureAD is not recognized as the name of a cmdlet, function, script file, or operable program

Here is the full error description:

Solution for Connect-AzureAD not recognized Issue:

The Azure Active Directory (Azure AD) PowerShell module provides a comprehensive set of cmdlets for managing users, groups, roles, applications, and other Azure AD resources. The module simplifies the management of Azure AD by enabling scripting and automation capabilities, instead of managing them in Web Browser through Azure Portal.

The error “Connect-AzureAD : The term ‘Connect-AzureAD’ is not recognized as the name of a cmdlet” typically occurs when the Microsoft AzureAD PowerShell module is not installed or not imported correctly. Here are a few steps that you can try to resolve this error:

Install the Azure AD Module:

The Connect-AzureAD cmdlet is part of AzureAD module. So, we have to install the module using the Install-Module command.

  1. Open PowerShell as an administrator, Enter:
    Install-Module AzureAD
    
  2. Confirm the installation by entering “A” – Yes to All, as in the below screenshot.
install azure AD module in powershell

After installing or updating the module, close and reopen your PowerShell session to refresh the environment and reattempt the connection. You can verify the installation using Get-InstalledModule or Get-Module command:

Get-InstalledModule AzureAD

#Alternatively: Get-Module -ListAvailable -Name AzureAD

Once installed, You should be able to connect to Azure AD using the Connect-AzureAD command.

Import-Module AzureAD

#Connect to Azure AD
Connect-AzureAD -Credential (Get-Credential)

#Get all users from Azure Portal
Get-AzureADUser

#Disconnect
Disconnect-AzureAD

Enter your username and password if prompted.

A similar error “Get-MsolUser : The term “Get-MsolUser” is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.” may occur when you try to execute the cmdlet from Azure AD PowerShell Module V1, and you got to install the MSOnline module to resolve.

Installing the PowerShell module to connect to Azure AD Office 365 is here: How to Connect to Azure AD using PowerShell?

A few more troubleshooting steps:

If you still get the same error, here is the troubleshooting checklist.

  • Check if the module is loaded to your PowerShell session using: Get-Module -Name AzureAD. If it’s not, try Importing the AzureAD PowerShell module to the current PowerShell session with Import-module command: Import-Module AzureAD
  • Make sure that you are running PowerShell as an administrator.
  • Try to reinstall AzureAD Module: If the module is installed but corrupted, or if you continue to face issues, consider uninstalling and then reinstalling the AzureAD module. Use Uninstall-Module AzureAD -Force followed by Install-Module AzureAD -Force
  • Ensure your PowerShell execution policy allows running scripts. You can check your current execution policy by running Get-ExecutionPolicy. If it’s set to Restricted, change it by running: Set-ExecutionPolicy RemoteSigned
  • Check your PowerShell version: The AzureAD module requires at least PowerShell version 5.1, so ensure you are running a compatible version of PowerShell.
  • The AzureAD module is primarily designed for Windows PowerShell 5.1. If you’re using PowerShell 7 or later, consider using the AzureAD.Standard.Preview module as a workaround.
  • Check for other modules that may conflict with AzureAD, and if there are any, remove or update them
  • Try to run the command in a different PowerShell session or in a different machine.

Wrapping up

In conclusion, the “Connect-AzureAD is not recognized” error is a common issue that occurs when the Azure Active Directory (Azure AD) PowerShell module is not properly installed or loaded in your PowerShell session. To resolve this error, you need to check if the module is installed, and if not, install it using the Install-Module cmdlet. After installation, import the module into your PowerShell session using the Import-Module cmdlet. Once the module is loaded, you can use the Connect-AzureAD cmdlet to connect to your Azure AD tenant and manage your Azure AD resources. Remember to run PowerShell as an administrator and ensure that your PowerShell execution policy allows running scripts.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *