If you encounter the following error “The term ‘Connect-MsolService’ is not recognized as the name of a cmdlet, function, script file, or operable program” while running the connect-MsolService cmdlet, this article is intended to help you to fix this problem. Mostly this error occurs due to the missing MSOnline Azure Active Directory PowerShell Module. MsolService command is part of the MSOnline PowerShell Module. It may also occur due to the corrupted MSOnline Module. This article will guide you to fix Connect-MsolService Not Recognized error message.
Fix Connect-MsolService Not Recognized error message:
First, make sure you have installed the MSOnline PowerShell module, if you haven’t installed it previously, follow the below-mentioned steps to install the MSOnline Module.
Solution 1: Install MSOnline PowerShell Module
Launch PowerShell in elevated mode, click on the start menu and search for PowerShell and right click on it, and choose Run as Administrator.
If you are running the PowerShell scripts for the first time then you’ll get an error, so run the following command first.
Set-ExecutionPolicy unrestricted
Type [Y]–> yes
Type [A]–>yes To All
Type [N]–> NO
Type [L]–>No to All
Type [S]–>Suspend
Type A and hit enter. Now you can run any script you want.
This command will allow you to run any script from the PowerShell, now you can install the Module without any error.
Next, To install the MSOnline PowerShell Module, run the following command from the PowerShell console.
Install-Module -Name MSOnline
Once the command is installed successfully, you have to import that MSOnline PowerShell module to your current PowerShell session. Type the following command to import the module.
Import-Module MSOnline
Once it executes successfully without any error, you can confirm that MSOnline module by typing the following command.
Get-Command -Module MSOnline
This command will return all cmdlets available in the MSOnline module. Now you can run the Connect-MsolService command with any error.
Solution 2: Reinstall MSOnline PowerShell Module
This error also occurs when the MSOnline PowerShell Module gets corrupted, in case if you already installed that module and it got corrupted, then use the following steps reinstall the MSOnline Module.
Open PowerShell in elevated mode and type the following command.
Uninstall-Module -Name MSOnline -Force
This command will uninstall the MSOnline module, to remove the module completely, run the following script.
Open the PowerShell ISE in elevated mode and copy and paste the following script.
$PSModulePaths = $Env:PSModulePath -split ";"
ForEach ($PSModulePath in $PSModulePaths) {
Get-ChildItem -Path $PSModulePath -Recurse -Directory -Filter "MSOnline" | Remove-Item -Force -Recurse
}
This script will remove all MSOnline-related files and folders, Next, reinstall the MSOnline PowerShell module by running the following commands one by one.
Install-Module -Name MSOnline
Import-Module MSOnline
Get-Command -Module MSOnline -Name Connect-MsolService
These commands will help you to install and import the Module and the third command will help you to verify the MSOnline module.
Read Also:
How to Install MSOnline PowerShell Module in Windows 11?