Bonus chatter: PowerShell and automated installs

Edit: When I wrote this post I didn’t know what the SC_IISSITE_ID parameter to the MSI was for. Since then I’ve discovered what it does. And it turns out that it and another parameter not discussed here are quite important if you want to install more than one instance of Sitecore on the same machine. If you want to make use of the automated approach below, you should also read my more recent post about the parameters.


I got a question on twitter the other day about how you might go about using the automated install ideas I posted recently in a PowerShell script.

I’m not much of a PowerShell user, but here are a couple of suggestions:

1) Running the commands as-is

It may not be the best way to do it (In fact, this post suggests loads of other approaches which might be better for you), but a quick test suggests that you can make some minor modifications to the example batch file and have it run as a .ps1 script instead. Basically you can explicitly call cmd.exe for each command you want to run from the batch file:

cmd.exe /c "Sitecore 6.6.0 rev. 140410.exe" /q /ExtractCab
cmd.exe /c "msiexec.exe" /qn /i "%cd%\SupportFiles\exe\Sitecore.msi" TRANSFORMS=":InstanceId5;:ComponentGUIDTransform5.mst" MSINEWINSTANCE=1 LOGVERBOSE=1 SC_LANG="en-US" SC_FULL="1" SC_INSTANCENAME="silent" SC_LICENSE_PATH="C:\Software\PartnerLicense-2013.xml" SC_SQL_SERVER_USER="sa" SC_SQL_SERVER="localhost" SC_SQL_SERVER_PASSWORD="p@55w0rd" SC_DBPREFIX="silent_" SC_PREFIX_PHYSICAL_FILES="1" SC_SQL_SERVER_CONFIG_USER="sa" SC_SQL_SERVER_CONFIG_PASSWORD="p@55w0rd" SC_DBTYPE="MSSQL" INSTALLLOCATION="C:\Inetpub\wwwroot\silent" SC_DATA_FOLDER="C:\Inetpub\wwwroot\silent\Data" SC_DB_FOLDER="C:\Inetpub\wwwroot\silent\Database" SC_MDF_FOLDER="C:\Inetpub\wwwroot\silent\Database\MDF" SC_LDF_FOLDER="C:\Inetpub\wwwroot\silent\Database\LDF" SC_NET_VERSION="4" SITECORE_MVC="1" SC_INTEGRATED_PIPELINE_MODE="1" SC_IISSITE_NAME="Silent" SC_IISAPPPOOL_NAME="SilentAppPool" SC_IISSITE_HEADER="silent" SC_IISSITE_PORT="80" SC_IISSITE_ID="13" /l*+v "%cd%\SilentInstall.log" 
cmd.exe /c rmdir /S /Q "%cd%\SupportFiles"

This seems to work when I test it, but it might be worth thinking about the TechNet post linked above in case one of the other approaches fits better with what you need to do.

2) Putting PowerShell variables in as parameters

This turns out to be easy – PowerShell is already quite clever at dealing with replacing variables for you.

$instanceName = "silent"
cmd.exe /c "Sitecore 6.6.0 rev. 140410.exe" /q /ExtractCab
cmd.exe /c "msiexec.exe" /qn /i "%cd%\SupportFiles\exe\Sitecore.msi" TRANSFORMS=":InstanceId5;:ComponentGUIDTransform5.mst" MSINEWINSTANCE=1 LOGVERBOSE=1 SC_LANG="en-US" SC_FULL="1" 
  SC_INSTANCENAME="$instanceName" 
  SC_LICENSE_PATH="C:\Software\PartnerLicense-2013.xml" SC_SQL_SERVER_USER="sa" SC_SQL_SERVER="localhost" SC_SQL_SERVER_PASSWORD="p@55w0rd" SC_DBPREFIX="silent_" SC_PREFIX_PHYSICAL_FILES="1" SC_SQL_SERVER_CONFIG_USER="sa" SC_SQL_SERVER_CONFIG_PASSWORD="p@55w0rd" SC_DBTYPE="MSSQL" INSTALLLOCATION="C:\Inetpub\wwwroot\silent" SC_DATA_FOLDER="C:\Inetpub\wwwroot\silent\Data" SC_DB_FOLDER="C:\Inetpub\wwwroot\silent\Database" SC_MDF_FOLDER="C:\Inetpub\wwwroot\silent\Database\MDF" SC_LDF_FOLDER="C:\Inetpub\wwwroot\silent\Database\LDF" SC_NET_VERSION="4" SITECORE_MVC="1" SC_INTEGRATED_PIPELINE_MODE="1" SC_IISSITE_NAME="Silent" SC_IISAPPPOOL_NAME="SilentAppPool" SC_IISSITE_HEADER="silent" SC_IISSITE_PORT="80" SC_IISSITE_ID="13" /l*+v "%cd%\SilentInstall.log" 
cmd.exe /c rmdir /S /Q "%cd%\SupportFiles"

Here the value for the SC_INSTANCENAME parameter in the call to msiexec.exe has been replaced with the variable name $instanceName. (I’ve broken the line to make this more obvious – you don’t want the extra whitespace in your script!) You can do the same trick for any other variables you need to introduce. And you can then use whatever PowerShell tricks you like to get the right value for that variable – read it from a file, accept it as a command line parameter etc. Just follow standard PowerShell patterns that you can find in a good book or TechNet post about PowerShell.

Advertisements

One thought on “Bonus chatter: PowerShell and automated installs

  1. Pingback: Automating uninstalls of Sitecore | Jeremy Davis

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s