Fix SharePoint PowerShell error - The term Get-SPweb is not recognized as the name of a cmdlet function script file or operable program


Problem

You receive below error executing PowerShell command/script while connecting to SharePoint site.

The term 'Get-SPweb' 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.
At line:1 char:10
+ ~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-SPWeb:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

⛏️ How to fix ?

The Site Url seems to be correct, so there is no problem with the script.

⚡️ SharePoint Management Shell

You need to start PowerShell as "Run as administrator"

⚡️ Windows PowerShell Console

If you directly run this PowerShell command from Windows PowerShell Console, the PowerShell module is not auto imported in console. Execute below command and then load the script.

Add-PSSnapin Microsoft.Sharepoint.Powershell
$spWeb = Get-SPWeb "[SharePoint Site link]"

⚡️ Windows PowerShell ISE

Execute below command and then load the script.

Add-PSSnapin Microsoft.Sharepoint.Powershell
$spWeb = Get-SPWeb "[SharePoint Site link]"

⚡️ SharePoint Online Management Shell

Get-SPWeb cmdlet is applicable only for SharePoint on-premise and will not work for SharePoint Online.
Refer PowerShell SharePoint Online commands or PnP PowerShell commands for working with SPO.

Get-SPOSite -Identity [SharePoint Online Site link]