Поделиться через


PowerShell: How To Install SharePoint Server 2010 Using PowerShell

In this post, I just want to take a few minutes to talk about how easy it is to install SharePoint Server 2010 binaries on a server using PowerShell. There are really only a few things that you need to know when you're considering installing SharePoint Server 2010 on a server. The first thing to understand is that we have to explicitly perform all of the same actions as if you were performing a GUI installation. This includes installing both the pre-requisites and the actual product itself.

Background

If you have wondered how to do this in the past, a quick search of your favorite search engine will return many examples. TechNet even has a great article describing how this can be done with SPModule titled Install SharePoint Server 2010 by using Windows PowerShell. Though the approach described in the article works, it just seems like quite a bit of work to do on each server for something that really should be done only once. It does however have some great tips for people who are new to PowerShell, and it's worth going over. The reason I looked into this is because I'm often building SharePoint labs from scratch, or co-workers need to spin up labs quickly, so it helps to have something reliable sitting around that you can just kick off while you work on other things.

Approach

What you need in your script will depend entirely on the state of your environment. The scenario that I'm illustrating here consists of SharePoint servers which have unrestricted access to the internet. This is very important, because SharePoint will automatically attempt to connect to the internet to download the latest version of each of the pre-requisites unless you tell it not to. I'm not going to illustrate that requirement in this blog post because it's very well documented in the TechNet article titled Install prerequisites from a network share (SharePoint Foundation 2010). The sample I'm providing can easily be adapted to include these arguments.

Solution

The solution is very simple in this case. There are two parts to this solution. The first step is installing the pre-requisites.

To facilitate the installation, I created two variables which should be set. This defines the config.xml location and the path to the installation binaries. This is accomplished by the following two lines:

$PathToConfigXML = '"C:\SharePointConfigurationFiles\config.xml"'
$BinaryPath = "D:"

Installing SharePoint Pre-requisites is relatively straightforward when your server is connected to the internet. This is accomplished using the following line:

cmd.exe /c "$BinaryPath\PrerequisiteInstaller.exe /unattended"

Now we get to installing SharePoint Server 2010. There are a few things you need to know first in order to accomplish this task. First is the location of your installation source, and second is the location of your config.xml file. I'm not going to spend too much time talking about finding the installation source because that's straightforward enough. The sample I'm providing takes only the path. For example, "D:". Choosing the right config.xml file can be more challenging. There are some samples provided with the SharePoint installation source. These are located in the 'files' subdirectory of the installation source, as shown in this screenshot.

 

Each of these directories has a config.xml file, with various options which can be interpreted by setup.exe. The one I typically use is 'SetupFarmSilent\config.xml'. The file looks like this once you've populated the Product Key (Enterprise Edition Trial Key shown below).

<Configuration>
<Package Id="sts">
<Setting Id="LAUNCHEDFROMSETUPSTS" Value="Yes"/>
</Package>
<Package Id="spswfe">
<Setting Id="SETUPCALLED" Value="1"/>
</Package>
<Logging Type="verbose" Path="%temp%" Template="SharePoint Server Setup(*).log"/>
<PIDKEY Value="VK7BD-VBKWR-6FHD9-Q3HM9-6PKMX" />
<Display Level="none" CompletionNotice="no" />
<Setting Id="SERVERROLE" Value="APPLICATION"/>
<Setting Id="USINGUIINSTALLMODE" Value="0"/>
<Setting Id="SETUP_REBOOT" Value="Never" />
<Setting Id="SETUPTYPE" Value="CLEAN_INSTALL"/>
</Configuration>

You can do a great deal more with the config.xml file, and that schema is documented in an article on TechNet titled Config.xml reference (SharePoint Server 2010).

Installing SharePoint is accomplished using the following line:

cmd.exe /C "$BinaryPath\setup.exe /config $PathToConfigXML"

As you can see, this process really isn't that difficult. Installing SharePoint Server 2010 can be accomplished by executing 4 lines of PowerShell.

You can download the script from this location: Download SharePointInstall.ps1 (zipped)


##
#This File Performs an Unattended Installation of SharePoint Server 2010
##

##
#Begin Setting Variables
##

$PathToConfigXML = '"C:\SharePointConfigurationFiles\config.xml"'
$BinaryPath = "D:"

##
#Begin Script Execution
##

Cls
Write-Progress -Activity "Installing SharePoint Server 2010" -Status "Installing Pre-Requisites"
cmd.exe /c "$BinaryPath\PrerequisiteInstaller.exe /unattended"
Write-Progress -Activity "Installing SharePoint Server 2010" -Status "Installing SharePoint Server 2010"
cmd.exe /C "$BinaryPath\setup.exe /config $PathToConfigXML"
Write-Progress -Activity "Installing SharePoint Server 2010" -Status "Completing SharePoint Server 2010 Installation"
Sleep 5
exit


 

Usage

This PowerShell script can run in any PowerShell console running as administrator. Future scripts (or 'scriptlets') will follow and provide general farm configuration steps and/or tips and tricks.

Feedback

As always, if you have any questions or feedback, let me know. If you have any ideas to optimize the script, I'd like to hear that too. Thanks for reading!

Comments

  • Anonymous
    April 10, 2012
    Nice write up Youngin.

  • Anonymous
    April 11, 2012
    The comment has been removed

  • Anonymous
    April 12, 2012
    Can you point me to any scripts for installing the various services as well and other configurations?

  • Anonymous
    April 12, 2012
    Bill, this is currently something I'm working on.  I'm creating a series of scriptlets (specific-purpose PowerShell scripts) that effectively walk through deploying all services and service applications, while also performing some of the actions people typically forget, such as adding the PortalSuperUser and PortalSuperReader accounts when creating a new web application.  Stay tuned!

  • Anonymous
    April 12, 2012
    I am collecting common task powershell scripts for SharePoint. then I may create a quick .net interface for it.

  • Anonymous
    April 16, 2012
    Try this autospinstaller.codeplex.com solution for a comprehensive installation of services, applications, and core bits.

  • Anonymous
    April 16, 2012
    The comment has been removed