Running remote Powershell scripts for SharePoint

I’ve been playing around with Powershell the last week and thought I’d post some of my trickier findings:

Remoting with powershell

With remoting you can script installations or configurations that should be done on multiple farms/servers without having to login to each farm and run the script with it’s variables. Now you can just build 1 big script with variables and run each part of the script with a remote powershell session opened with the correct credentials.

The code below calls some functions to start a new remote session with fixed name, load variable / functions file into the session to be used later, run your code using the variables and functions, end session.

StartRemoting $AUTH_Servername $AUTH_ServerUser $AUTH_ServerUserPassword

            $s = Get-PSSession -Name "RemoteSP2010Script"

            Invoke-Command -Session $s -ScriptBlock {


                                                #YOUR CODE


            StopRemoting $AUTH_Servername



function LoadSharePointCmdlets()



Write-Host "- Loading SharePoint cmdlets" -foregroundcolor "Green"

Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue



function StartRemoting($Server, $Username, $Password)


    #Build credentials from variables

    if($Username -eq $NULL)


        $Credentials = $NULL




        $Credentials = New-Object -TypeName System.Management.Automation.PSCredential 

                                                        -argumentlist $Username , $Password 



    #enable remoting

    enable-PSRemoting -confirm:$false


    #increase memory limit for remote shell

    Set-Item WSMan:\localhost\Shell\MaxMemoryPerShellMB 1000 


    #Disconnects the client remote desktop

    #Enable-WSManCredSSP -Role client -DelegateComputer $Server -Force


    Write-Host "Starting new remote session to" $Server -foregroundcolor "Green"

       if ($Credentials -eq $NULL)  


            $s = new-psSession -ComputerName $Server -Name "RemoteSP2010Script"




           $s = new-psSession -ComputerName $Server -Authentication CredSSP

                                       –Credential $Credentials -Name "RemoteSP2010Script"



    #Load Variables & functions into remote session

    Write-Host "Loading variables and functions into remote session"  -foregroundcolor "Green"


    Invoke-Command -Session $s -FilePath $VariableFileLocation -ErrorAction SilentlyContinue

    Invoke-Command -Session $s -FilePath $FunctionsFileLocation -ErrorAction SilentlyContinue



function StopRemoting($Server)


    Write-Host "Closing remote session to" $Server -foregroundcolor "Green"

    Remove-PSSession -ComputerName $Server



SharePoint 2010 web applications with host header eventID 4625 – 0xc000006d

I made a new web application today on my SharePoint 2010 development machine through Central Administration and entered a Fully qualified domain name FQDN as url like http://company.intranet and added the mapping in my host file.

When trying to connect to my new web application / root site collection I got a pop-up windows asking my login 3 times after which I just got a blank screen.

I ping’ed the url and it did return my IP so I was sure the address lookup was correct.

In the event viewer I could see an error with eventID 4625 and error 0xc000006d.

Turns out this is quite normal and by design, it’s a safety precaution in IIS. I found the solution on thisblogpost.

When you use integrated authentication and you have the website as a local IIS site, then you will only be able to access the website using the machine name (http://codejourney). You will not be able to access it using a FQDN.

How to disable loopback check for local IIS websites:

There are 2 ways to get past this annoyance.

Both solutions require registry editing, so remember to create a backup first.
Solution 1 (Preferred): Specify which host names that does not cause loopback check.

1: Open up the registry editor by typing regedit under Run.
2: Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa\MSV1_0
3: Right-click MSV1_0 and click New and choose to make it a Multi-String Value.
4: Enter BackConnectionHostNames as name for the entry, and double-click it to modify it.
5: Type the hostnames you need to use ( for instance).
6: Restart IISAdmin Service (“Start” -> “Administrative Tools” -> “Services”)

Solution 2 (Not recommended):
1: Open up the registry editor by typing regedit under Run.
2: Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
3: Right-click Lsa and click New and choose to make it a DWORD Value.
4: Enter DisableLoopbackCheck as name for the entry, and double-click it to modify it.
5: Set the value to 1 and click OK


My first CodePlex project: Timerjob dynamic settings – creation – deletion in Central Administration.


Today I created my first CodePlex project. It’s a fun SharePoint (2007 so far) project for managing timerjobs.

– You can add custom timerjob definitions to a namespace in the project and whatever public property’s you want. There is one example of a dummy definition with dummyProperty.

– The project creates 2 application pages available from central administration through the operations tab with the rest of the timerjob settings.

TVR timerjob creation page

First page is for creating instances of a timerjob definitions from your project. A dropdown list will display all available timerjob definitions in your project.

When you select one the page will dynamically show all public variables of the definition in the page with a label and textbox for each.

You can choose a name and schedule for the instance, and set property’s (that are saved in the SPPropertybag of the Central Admin site starting with the name of your instance + property name).

TVR timerjob settings page

This page shows you a dropdown list of all (custom) timerjob instances running on the Central Admin web application. If you’ve created the instance using the first page then it will definitely be displayed here.

You have the option to set a new schedule for the instance.

The page dynamically loads all available property’s used by the timerjob instance and shows the values in textboxes so you can edit them.

There are also buttons to delete the current timerjob instance or run it now! (Which I desperately miss in SharePoint 2007)

You can find more info and the source code + wsp package at CodePlex.

Please feel free to comment as it’s a first version. Also if you find it a useful tool or how you’d go about things in another ways.