When configuring task scheduler to run the SharePoint management shell it opens as windows powershell not in SharePoint management shell.

The script I made is running well under SharePoint management shell but not in windows powershell.

When opening the target file location of SharePoint management shell it points the same .exe as windows powershell. how is that possible.


You need to add the PSSnapin for Microsoft SharePoint Server. Just add the following line to the beginning of your script.

Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue

Without this Snapin, the powershell does not know commands like Get-SPxxx.

| improve this answer | |
  • what? i was searching a lot and now i found it. thanks for the help. you my nigga. – listojay Nov 14 '16 at 13:42

SharePoint Management Shell in start menu is actually a shortcut to regular powershell with some predefined startup script.

If you open properties for this shortcut you will find something like this:

C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe  -NoExit  " & ' C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\15\CONFIG\POWERSHELL\Registration\\sharepoint.ps1 ' "  

This sharepoint.ps1 is in charge for "enabling" SharePoint cmdlets in regular PowerShell. Here is the content of sharepoint.ps1

$ver = $host | select version
if ($ver.Version.Major -gt 1)  {$Host.Runspace.ThreadOptions = "ReuseThread"}
Add-PsSnapin Microsoft.SharePoint.PowerShell
Set-location $home 
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.