Problem: When trying to connect to SharePoint Online through PowerShell cmdlet: Connect-SPOService -URL https://crescent-Admin.SharePoint.com, got an error message and could not connect to SharePoint Online from PowerShell:
Connect-SPOService : The term ‘Connect-SPOService’ 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.
This error message indicates that the particular cmdlet doesn’t exist in the loaded modules. In this case, this error is because the “Connect-SPOService” cmdlet is part of SharePoint Online Management Shell (or SharePoint Online PowerShell Module), and it is not loaded! So, to resolve this issue: You have to install either the SharePoint Online Management Shell (less recommended) or SharePoint Online PowerShell Module (Preferred) before using the cmdlet Connect-SPOService.
You can download and install SharePoint Online Management Shell to your client machine from https://www.microsoft.com/en-us/download/details.aspx?id=35588
If it’s already installed, try uninstalling and then re-installing.
Double-check if the SharePoint Online PowerShell Module is installed by:
Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | Select Name,Version
You can install the SharePoint Online PowerShell Module with:
For un-installation, use:
Uninstall-Module -Name Microsoft.Online.SharePoint.PowerShell -AllVersions -Force
Although we don’t have to explicitly load the module in PowerShell with “Import-Module Microsoft.Online.SharePoint.Powershell”, give it a try to expose any potential issues.
If you are trying to connect to SharePoint Online PowerShell through a proxy server, the Connect-SPOService cmdlet connections fail! You have to use:
#Get Credentials to connect $cred = Get-Credential [System.Net.WebRequest]::DefaultWebProxy.Credentials = $cred Connect-SPOService -Url "https://<Tenant-admin>.sharepoint.com" -Credential $cred
In another situation, I had to delete all SharePoint Online client Assemblies from the GAC and then install the SharePoint Online PowerShell Module:
- Navigate to “C:\Windows\Microsoft.NET\assembly\GAC_MSIL”
- Select all folders starting with name “Microsoft.SharePoint.Client” and delete them all!
- Finally, Install the PowerShell Module for SharePoint Online: Install-Module Microsoft.Online.SharePoint.PowerShell -force
Make sure you have closed all PowerShell/PowerShell ISE instances before performing the above steps.