41

I just typed the follow to try and get my SharePoint site:

$spWeb = Get-SPWeb -Identity "http://nycs00058260/sites/usitp"

It gave me the following error

The term 'Get-SPWeb' is not recognized as the name of a cmdlet, function, script...

The url is correct so why am I getting this error?

skeletank
  • 2,880
  • 5
  • 43
  • 75
LifeScript
  • 1,116
  • 5
  • 15
  • 24

3 Answers3

77

I think this need to be run from the Management Shell rather than the console, it sounds like the module isn't being imported into the Powershell console. You can add the module by running:

Add-PSSnapin Microsoft.Sharepoint.Powershell

in the Powershell console.

nimizen
  • 3,345
  • 2
  • 23
  • 34
  • Great! This allow us to use Windows PowerShell ISE for SharePoint related stuff, which is much better as it support multi-line functions and has syntax validation! – Lennon Mar 04 '15 at 18:18
  • 2
    Hi, I am getting error while running the mentioned command. Please check this error:Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 4. At line:1 char:1 + Add-PSSnapin Microsoft.Sharepoint.Powershell + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (Microsoft.Sharepoint.Powershell:String) [Add-PSSnapin], PSArgumentException + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand – Harsha Vardhini Nov 09 '18 at 05:42
  • 3
    @HarshaVardhini I am getting the same error but for PowerShell version 5. Did you figure out the problem? – Zack May 06 '19 at 16:00
10

Run this script from SharePoint 2010 Management Shell as Administrator.

garec
  • 487
  • 5
  • 7
  • hi, I have a small question, how to check if the file already exists in sharepoint lib? – LifeScript Dec 04 '12 at 20:11
  • if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorActionSilentlyContinue) -eq $null) { Add-PSSnapin "Microsoft.SharePoint.PowerShell" } – Eliezer Feb 15 '18 at 22:33
7

Instead of Windows PowerShell, find the item in the Start Menu called SharePoint 2013 Management Shell:

enter image description here