Remote Session to Sharepoint 2013 Using PowerShell

Morning again, this is another of my powershell and SharePoint moment.

So, I was getting sick and tired of having to always be on the server using remote desktop to work on powershell and SharePoint so I decided to investigate on how to make that happen. I knew that I can use WSMan to connect but wasn’t sure how. So I went back to my good old friend Get-Help for powershell. After some digging around I found out what I had to do.

To be able to connect to your remote server to work with SP and powershell the server itself must have PSRemoting enable. To do this I ran the: 

Enable-PSremoting -Force

After running this I enabled WSManCredSS to allow my server to receive the credentials that are being passed through.

On the server side I ran: 

Enable-wsmancredssp -role server

And also ran the same command but this time for the client

enable-wsmancredssp -role client -delegatecomputer *.domain.com

Client Side:

I ran this as well

Enable-PSremoting -Force

enable-wsmancredssp -role client -delegatecomputer *.accounting.fabrikam.com

 

Once all the prep work was done I then wrote up my little script to allow me to connect. Here it is:

# #######################################################
# SPRemoteConnect.ps1
# Johny
# Sept. 8, 2013
# This to connect to Remote SharePoint Server using Powershell
# and also add the Snapin to allow it to work
# #######################################################

#username to be used
$cred = “doman\username”

#Server to connect to: this one will prompt user for a server name
$server = Read-Host “Which server to connect to”

#Create a new session variable $s using $cred and $server
$s = New-PSSession -ComputerName $server -Authentication Credssp -Credential $cred

#Invoking command to Add-PsSnapin Microsoft.SharePoint.PowerShell
Invoke-Command -session $s -scriptblock {Add-PsSnapin Microsoft.SharePoint.PowerShell}

#Enter the session to start working
Enter-PSSession -session $s

 

Just thought I shared what I found out, if any of you have a much easier and better way of doing this please share.

Thank you

Be the first to comment

Leave a Reply

Your email address will not be published.


*