Enable Remoting support on SharePoint Server box
- Enable Windows PowerShell Remoting
- Increase memory limit for remote shell (Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1000)
- Setup CredSSP support
Setup client machine for Remoting
- Enable CredSSP support
- Store and use credentials for scripting
A credential in Windows PowerShell is a object which contains username (as plain text) and password (as secure string).
First, use the following command to covert password from keyboard input to a secure string in a text file.
Read-Host -AsSecureString | ConvertFrom-SecureString | out-file C:\crd-sharepoint.txt
When you need to create a credential object, read this password (the secure string) from the file and create the credential with the following command:
$pwd = Get-Content C:\crd-sharepoint.txt | ConvertTo-SecureString
then create the credential (replace myusername with your domain\username):
$crd = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "myusername",$pwd
Then you will be able to use this credential in the command line without any dialogue.
Enter-PSSession -ComputerName sharepoint.contoso.com -Authentication CredSSP -Credential $crd
3. Load SharePoint Windows PowerShell Snap-in