Tuesday, December 6, 2022

Installing and importing SharePoint Online Management Shell to remove a Deleted SharePoint site

I typically do not work within the SharePoint Online space but would periodically be asked to assist with administrative tasks and one of the issues I constantly face is not finding the right cmdlets to perform what I need to do but rather installing and importing the SharePoint Online Management Shell. My colleagues seem to encounter this as well so I thought I’d write a short blog post to outline the steps to get the module installed and demonstrate how to delete a deleted SharePoint site as an example.

Problem - Installing and Importing the SharePoint Online Management Shell

The official Microsoft document demonstrates the process of installing the module here:

Get started with SharePoint Online Management Shell

The article provides the following cmdlets:

Get-Module -Name Microsoft.Online.SharePoint.PowerShell -ListAvailable | Select Name,Version

Install-Module -Name Microsoft.Online.SharePoint.PowerShell

What this article does not provide is the cmdlet to import the module after installing it as it will then provide the following cmdlet to connect to SharePoint Online:

Connect-SPOService -Url -Credential

Attempting to immediately connect will throw the following error:

Connect-SPOService: The term 'Connect-SPOService' is not recognized as a name of a cmdlet, function, script file, or executable program.

Check the spelling of the name, or if a path was included, verify that the path is correct and try again.


Attempting to import the module with the following cmdlet will yield no output in the PowerShell console:

Import-Module Microsoft.Online.Sharepoint.Powershell –DisableNameChecking


Then trying to use the Connect-SPOService again will display the following error:

Connect-SPOService: The remote server returned an error: (400) Bad Request.



Before attempting to connect to SharePoint Online, the following cmdlet needs to be executed import the module:

Import-Module Microsoft.Online.Sharepoint.Powershell -UseWindowsPowerShell


Once authenticated and connected, you should now be able to execute cmdlets such as the following to remove a deleted SharePoint site that has its associated Microsoft 365 group removed:

Remove-SPODeletedSite -Identity


The site can’t be permanently deleted because it’s connected to a Microsoft 365 group


Hope this helps anyone who might be looking for a quick answer to install, import, and connect to SharePoint Online via PowerShell.


Smtp Server For Bulk Email said...

Nice Blog...Waiting for the Next Update…
smtp mail services
smtp server provider


Merak123 Slot Online

Merak123 Slot Resmi

Merak123 Slot Gacor

Codermaolw said...

buy SMTP with credit card

buy smtp server with bitcoin

Smtp Relay Service Provider said...

Nice Blog...Waiting for the Next Update…
bulk email server provider

Damo said...

Amazing! I was going round and round with this exact same issue for ages. I knew it was something to do with how my credentials were being passed using VS Code because i could run the script line by line in powershell. I was originally importing-module but with -DisableNameChecking but as soon as i changed it to -UseWindowsPowerShell that resolved it!

Thank you * much appreciated!