In this tutorial, I will explain how to fix an error: The term Get-SPweb is not recognized as the name of a cmdlet function script file or operable program. If you are working with the SharePoint on-premises version, you might receive this error while working with PowerShell SharePoint.
The term ‘get-spweb’ is not recognized as the name of a cmdlet function script file
Let me first explain when I got this error in SharePoint.
Recently, I was trying to retrieve all the subsites of a SharePoint On-Premsies site by using Get-SPWeb PowerShell cmdlet.
If you are new to this, then:
Get-SPWeb is a PowerShell cmdlet used in SharePoint Server (on-premises) to retrieve all the SharePoint subsites. It is part of the SharePoint Management Shell and is commonly used for managing and interacting with SharePoint objects programmatically.
The basic syntax of the Get-SPWeb cmdlet is:
Get-SPWeb -Identity <SiteUrl>For example:
$web = Get-SPWeb -Identity "http://sharepoint/sites/demo"I was running the exact cmdlet like below:
$web = Get-SPWeb "http://win-pfcp2dgt8di/sites/EnjoySharePoint/"But, it gave the error as:
Get-SPWeb : 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:8
+ $web = Get-SPWeb “http://win-pfcp2dgt8di/sites/EnjoySharePoint/”
+ ~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-SPWeb:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
You can also follow the below screenshot of how this error looks:

Solution
The error usually occurs if you run the command directly in the Windows PowerShell Console.
To fix this error, you must first execute the below cmdlet in PowerShell.
Add-PSSnapin Microsoft.Sharepoint.PowershellIdeally, we should run in SharePoint Management Shell rather than only in the PowerShell console. So, Open SharePoint Management Shell in Administrator mode and then run the Cmdlet; the error will not come.

If you are using the Windows PowerShell ISE to run, debug, or test PowerShell cmdlets, then you can write the script like the below:
Add-PSSnapin Microsoft.Sharepoint.Powershell
$web = Get-SPWeb "http://win-pfcp2dgt8di/sites/EnjoySharePoint/"After this, the error will not come. This way, you can fix the issue.
Key Points to Remember While Working With Get-SPWeb
From my experience, let me explain some key points you should remember while working with Get-SPWeb in PowerShell SharePoint.
- Get-SPWeb only works with SharePoint on-premises environments (e.g., SharePoint Server 2013, 2016, 2019). It does not apply to SharePoint Online, where the SharePoint PnP PowerShell module should be used instead.
- The returned SPWeb object should be properly disposed of after use to free up system resources. This can be done using the .Dispose() method like: $web.Dispose()
- If you need to work with the root site collection, use Get-SPSite instead.
You may also like:
- Get All SharePoint Site Collections Using PowerShell
- Get Site Template in SharePoint Using PowerShell
- Get SharePoint Site Members Using PowerShell
- Delete a SharePoint Online Site Using PowerShell

After working for more than 18 years in Microsoft technologies like SharePoint, Microsoft 365, and Power Platform (Power Apps, Power Automate, and Power BI), I thought will share my SharePoint expertise knowledge with the world. Our audiences are from the United States, Canada, the United Kingdom, Australia, New Zealand, etc. For my expertise knowledge and SharePoint tutorials, Microsoft has been awarded a Microsoft SharePoint MVP (12 times). I have also worked in companies like HP, TCS, KPIT, etc.
Getting this error:Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 5.
Kindly help