5

How I can add Add-PSSnapin Microsoft.SharePoint.PowerShell to machine without SharePoint 2010? I try to run PowerShell script to Backup Farm on Windows Server 2008 R2 without Sharepoint but while I open PowerShell and try to run script I always have error:

Add-PSSnapin : No snap-ins have been registered for Windows PowerShell version 2. At line:1 char:13 + Add-PSSnapin <<<< Microsoft.SharePoint.PowerShell + CategoryInfo : InvalidArgument: (Microsoft.SharePoint.PowerShell:String) [Add-PS ption + FullyQualifiedErrorId : AddPSSnapInRead,Microsoft.PowerShell.Commands.AddPSSnapinCommand

2 Answers 2

5

You can also do Implicit Remoting, which allows you to import all of the SP10 Powershell commands into a local session. The method described above works as well, but you are essentially running the commands from the server, so if you are on a server with different modules (such as Exchange 2010) you will have a difficuly time running those on the SharePoint server. You still have to enable psremoting and credssp (to avoid double hop), but this allows you to create a module, which can be imported (and set to automatically do so) every time you open powershell. Let me know if you need any help!

# Only need to do this part for initial setup for storage of username and pwd and to turn on the Powershell remoting feature
Enable-PSRemoting
Enable-WSManCredSSP -Role client -DelegateComputer *
# If you want to save credentials for an account (credentials need to be specified using CredSSP Auth). Only need to run once
Read-Host -AsSecureString | ConvertFrom-SecureString | out-file C:\crd-sharepoint.txt 
# Type Password Here 
# You could add this to a logon script to automatically import the sharepoint powershell commands into your session
$pwd = Get-Content C:\crd-sharepoint.txt | ConvertTo-SecureString
$crd = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "domain\username",$pwd
$session = New-PSSession servername -Authentication CredSSP -Credential $crd  
Invoke-command $session {Add-PSSnapin Microsoft.SharePoint.Powershell}
# Only import the session if you do not want to export it into a module for future use 
Import-pssession -session $session

#This takes a minute or so to spin up so you could save it to disk.     
Export-PSSession -Session $session -OutputModule "SP2010" -CommandName *-SP*

#Import Saved file from disk
Import-Module SP2010
3
  • On which server I have to run above script? And is it enought to use this script only one time? Best regards
    – Wilon
    Commented Oct 25, 2012 at 19:40
  • All of the code I posted above needs to be ran on the client. You can set this up to save it as a powershell module named "SP2010" and then add the module to your powershell profile so it loads at startup. See this link for setting up a profile. These 2 entries still need to be ran (posted by Falak) on the SP10 server you are remoting/importing the commands from: Enable-PSRemoting Enable-WSManCredSSP -Role Server
    – ajbillings
    Commented Oct 26, 2012 at 13:34
  • Ok, I try to do it. Once more thanks for tour help :) I let you know about progress in my case...
    – Wilon
    Commented Oct 26, 2012 at 13:35
4

No! you can't do that without SharePoint Installation, or with a client that could be connected to SharePoint Server

In order to run Windows PowerShell remote you have to enable Windows Remote Management on the Server running SharePoint 2010 and the client that you want to run the commands from.

On SharePoint Server

Enable-PSRemoting

Once remoting is enabled on the server you should enable CredSSP.

Enable-WSManCredSSP -Role Server

On the client you should enable remoting and CredSSP

Enable-PSRemoting
Enable-WSManCredSSP -role client -delegatecomputer SPServer.domain.local

When starting a remote session run the following command:

Enter-PSSession -ComputerName SPServer.domain.local `
-Authentication CredSSP -Credential domain\user

To access all the great SharePoint 2010 cmdlets through a remote session you first have to add the SharePoint2010 snap-in

Add-PSSnapin Microsoft.SharePoint.PowerShell

Once the snap-in is added you can run all the SharePoint cmdlets available in SharePoint 2010.

When you’re done you can end the session through the Exit-PSSession cmdlet.

Exit-PSSession

See Nikal Goude blog for more details

3
  • Thanks for you support, this is very helpful for me. But should I do it every time when I would like to run PowerShell script on miche without SP?
    – Wilon
    Commented Oct 25, 2012 at 13:59
  • Yeah, it needs to be done every time you run a new PowerShell session. Commented Oct 25, 2012 at 14:03
  • It will be hard to me because I would like to add Task Sheduler to run Backup Farm script on machine without SP? I can't to do it on SP machine because I have problem with Policy. And I would like to do automatic without me of course . Is it any different way to do it? It is very important to me. Really thaks you for help,
    – Wilon
    Commented Oct 25, 2012 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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