Skip Ribbon Commands
Skip to main content
Sign In
SharePoint Program Manager, Infrastructure
Zach Rosenfield's SharePoint Blog > Posts > Remote Install of SharePoint (with SPModule)
December 23
Remote Install of SharePoint (with SPModule)

Earlier in the week I posted about SPModule, which greatly simplifies setting up a SharePoint farm.  But when you pair this functionality with PowerShell remoting—the real “power” shines.   I’m going to show you how, after a couple of initial setup concepts, you can setup a multi-machine farm with just a few lines of PowerShell!

Prereqs: Remoting
The only pre-requisite for this exercise is having PowerShell 2.0 RTM installed and enabled for remoting.  PowerShell bits are available for earlier versions of Windows Server
here—but should already be ready on your Windows 2k8 R2 installs.

Then, to enable PowerShell Remoting for SharePoint you need to open up the SharePoint Console “As an Administrator” on EACH machine that will be receiving remote commands (i.e.: all machines for the farm) and run the following commands:

      Enable-PSRemoting -force

      Enable-WSManCredSSP –role Server -force

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

 

                Note - the above commands are doing the following in this order:
                                1. Enabling Remoting  (WSMan)
                                2. Enable CredSSP support in WSMan
                                3. Increases the local memory limit to 1000 MB (I recommend somewhere between 512 to 1000 MB)

Finally, from the machine that will be executing the remote commands, you need to run the following commands to enable client-remoting.  I’m going to use the “Admin Machine” (which is essentially the first machine in my farm) as the initiator of the script—but you can also use a machine that is not going to be part of the farm. 

Enable-PSRemoting -force

      Enable-WSManCredSSP –role Client –DelegateComputer “<MACHINE>” -force

 

The DelegateComputer parameter needs to be updated with an expression or machine(s) that will be delegated to.  If you want to delegate across the domain, you could write “*.mydomain.com”.  Additionally “*” can be used to easily pass this step, but this is very bad security-wise (it allows credential delegation to all machines). 

Share SPModule
The last step to getting prepared—is sharing out the folder that contains SPModule (e.g.: \\servername\spmodule), which you can
install according to my last post. 

The Install
Now for the fun! The script is really split into two pieces, installing SharePoint and creating the farm on the local machine (my “Admin Box”) and then joining the rest of the machines to the farm.   So, let’s begin.  I’ll go through all the steps and then present the whole script together—keep in mind I’ve kept his pretty simply so error handling and additional logic is “an exercise for the reader”:

1.       Define the additional machines we are using

$machinelist = ('machine1','machine2')

 

2.       Get the credential to use for remoting

$cred = Get-Credential

 

3.       Load the Modules (from our share)

$env:PSModulePath = “\\ServerName\SPModule;” + $env:PSModulePath

Import-Module SPModule.misc

Import-Module SPModule.setup

 

4.       Install SharePoint on the local box:

Install-SharePoint -SetupExePath \\servername\SharePoint2010-Beta\setup.exe” -PIDKey “PKXTJ-DCM9D-6MM3V-G86P8-MJ8CY”

 

5.       Install SharePoint on the remote boxes, which means:

a.       Create our script to run remotely which will load the modules and call “install”

b.      Connect to the remote machines and execute the script:

$script = {$env:PSModulePath = \\ServerName\SPModule;” + $env:PSModulePath;

Import-Module SPModule.misc; Import-Module SPModule.setup;

Install-SharePoint -SetupExePath \\servername\SharePoint2010-Beta\setup.exe -PIDKey “PKXTJ-DCM9D-6MM3V-G86P8-MJ8CY”

}

$machinelist |%{ Invoke-Command -ComputerName $_ -Credential $cred -Authentication Credssp -ScriptBlock $script -AsJob  }

 

                Helpful Hints: If your jobs are failing right away, remove the “AsJob” to see the error inline.  Also, if your jobs are failing after a long period of time, you may be needing a reboot during your install.  You can do this by sending a restart-computer to the script block above, then waiting for the remote machine to reboot and call install again.  Alternatively you can make sure your initial Windows image has enough prereqs to avoid a reboot.

6.       We did the above commands as a job (so they could run in parallel) so now we need to wait for them to complete…

While((Get-Job -State Running) -ne $null){ Write-Progress "Install Jobs are being completed" -Status "Please Wait..." -PercentComplete 0; sleep 30 }

 

7.       And now we can deploy the farm locally:

   New-SharePointFarm –DatabaseAccessAccount ($cred) –DatabaseServer “SQL01” –FarmName “TestFarm”

 

8.       And then join the rest of the machines (we need to do this one at a time on this one to keep things “okay”!).  Unfortunately, this will prompt you for the passphrase (it’s the password of the user account you’re prompted for in step 2).  You can add “-PassPhrase <yourpassword>” to keep this from prompting, but it will put your password in plaintext; I’ll try to blog about a workaround for this in another post.

$script = {$env:PSModulePath = “\\ServerName\SPModule;” + $env:PSModulePath;

Import-Module SPModule.misc; Import-Module SPModule.setup;

      Join-SharePointFarm -DatabaseServer “SQL01” -ConfigurationDatabaseName “TestFarm_SharePoint_Configuration_Database”

}

$machinelist |%{ Invoke-Command -ComputerName $_ -Credential $cred -Authentication Credssp -ScriptBlock $script }

 

9.       Done!

Here’s the full script—just change the machines, paths, sql machine name, and farm name (highlighted items)—then go grab some coffee!  When you return you'll be a couple PassPhrases away from a multi-machine farm!

$machinelist = ('machine2','machine3'#machine1 is the local machine

$cred = Get-Credential

$env:PSModulePath = \\ServerName\SPModule;” + $env:PSModulePath

Import-Module SPModule.misc

Import-Module SPModule.setup

 

Install-SharePoint -SetupExePath \\servername\SharePoint2010-Beta\setup.exe” -PIDKey “PKXTJ-DCM9D-6MM3V-G86P8-MJ8CY”

 

$script = {

$env:PSModulePath = \\ServerName\SPModule;” + $env:PSModulePath;

Import-Module SPModule.misc; Import-Module SPModule.setup;

Install-SharePoint -SetupExePath \\servername\SharePoint2010-Beta\setup.exe” -PIDKey “PKXTJ-DCM9D-6MM3V-G86P8-MJ8CY”

}

$machinelist |%{ Invoke-Command -ComputerName $_ -Credential $cred -Authentication Credssp -ScriptBlock $script -AsJob  }

 

While((Get-Job -State Running) -ne $null){ Write-Progress "Install Jobs are being completed" -Status "Please Wait..." -PercentComplete 0; sleep 30 }

 

   New-SharePointFarm –DatabaseAccessAccount ($cred) –DatabaseServer SQL01 –FarmName TestFarm

 

$script = {$env:PSModulePath = \\ServerName\SPModule;” + $env:PSModulePath;

Import-Module SPModule.misc; Import-Module SPModule.setup;

            Join-SharePointFarm -DatabaseServer SQL01 -ConfigurationDatabaseName TestFarm_SharePoint_Configuration_Database”

}

$machinelist |%{ Invoke-Command -ComputerName $_ -Credential $cred -Authentication Credssp -ScriptBlock $script }

 

Note: for the truly adventurous, you can enhance this script greatly by including VM management.  I’d recommend looking at this project for ideas…

Comments

Great Zach

You are my hero, enbaling what I envisioned few years ago.
 on 1/11/2010 12:01 AM

DB names

Zach, when SharePoint Server Enterprise the installer automatically creates DB names+GUID for each of the services.  How can we change the DB+GUID to something our DBA's will permit? 
 on 5/3/2010 11:24 AM

Prerequisites

Everything described above works great, thank you, with one exception. We are not able to get the prerequisites to install through Install-SharePoint through the remoting described above.

Do you already have the prerequisites installed in the scenario you describe above, is Install-SharePoint installing them for you through the remote session?

We would like to know whether this is even possible, or if we are just heading in the wrong direction and should instead shift our efforts to scripting installing the prerequisites before running Install-SharePoint
 on 8/13/2010 2:01 PM

Restart remote computer

I tried running this script a couple of times and everything runs fine in the local box but the only thing that gets installed in the remote box is one of the prerequisites (SQL 20087 Native Client). I assumed that the problem is that it needs a reboot, but I can't make the restart-computer work when I place it inside of the $script block.

So, basically I'm not really sure where in the script to put my restart-computer clause for the remote boxes. Could you help me out?

Thank you for your time!
 on 1/20/2011 2:18 PM

Restart remote computer

I tried running this script a couple of times and everything runs fine in the local box but the only thing that gets installed in the remote box is one of the prerequisites (SQL 20087 Native Client). I assumed that the problem is that it needs a reboot, but I can't make the restart-computer work when I place it inside of the $script block.

So, basically I'm not really sure where in the script to put my restart-computer clause for the remote boxes. Could you help me out?

Thank you for your time!
 on 1/20/2011 2:31 PM

Restart remote computer

schedule a task to reboot the computer.
 on 9/13/2012 4:10 PM

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Comments *


Name (required) *


Human Test


Checking if you're human: enter "1234" (no quotes)

Attachments