The Term Get-SPweb Is Not Recognized As The Name Of A Cmdlet Function Script File

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:

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

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.Powershell

Ideally, 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.

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

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:

  • >

    Build a High-Performance Project Management Site in SharePoint Online

    User registration Power Apps canvas app

    DOWNLOAD USER REGISTRATION POWER APPS CANVAS APP

    Download a fully functional Power Apps Canvas App (with Power Automate): User Registration App

    Power Platform Tutorial FREE PDF Download

    FREE Power Platform Tutorial PDF

    Download 135 Pages FREE PDF on Microsoft Power Platform Tutorial. Learn Now…