How to Install Sitecore, Clone Git Repository, and Deploy Code with PowerShell

Vasiliy Fomichev

In Installation Posted

It turns out that PowerShell and Sitecore go hand in hand together! In this article we will look at how we can use PowerShell to automate the manual install of Sitecore and clone a project from a Git repository. This script comes in very handy when developers join the project, making the development environment setup a matter of about 10 minutes with a good internet connection.

 Why use PowerShell for Sitecore setup?

After reading the Agile Development chapter on 10 minute builds,it made me think about automating the Sitecore installation. Some may argue “But there is already an executable, why try reinventing the wheel with PowerShell?” Here is why –

  • The PowerShell installation is less intrusive than the executable to the Operating System
  • PowerShell script gives you control over every step in the installation
  • PowerShell Sitecore installation script is extensible and scalable
  • The installation can be scripted to include all required settings making the installation process a matter of a double-click or a single command (ideal for developer onboarding)
  • PowerShell installation can be used with many popular source control repositories to automatically checkout and rebuild the code
  • PowerShell installation can also be used with TDS projects, automating content deployment

 Sitecore PowerShell Installation Script

The idea of substituting hours of Sitecore installation training, team project setup sessions, installation documentation creation with just 10 minutes, sounded pretty good to me, so I set off into the world of PowerShell.

As any sane developer, I first researched the topic, which turned out Alex Shyba’s blog artice on PowerShell , which is now hosted on Git Hub. It did something similar to what I was looking for, however, it lacked flexibility, error checking, and functionality for working with source control. Since the project was not copyrighted, I bravely borrowed the idea of the install.config and versions.config  files.

  • Install.config contains configuration required for the cript. Things like .NET version, download paths, logins…etc.
  • Versions.config contains a list of available Sitecore versions for installation. Configuration attributes such as latest and recommended allow shortcut installs of the latest and recommended Sitecore instances without knowing exact versions and revisions.

 PowerShell Script Functionality

After an evening of hacking the script was modified to include the following additional functionality:

  1. Enabling MVC on 6.x Sitecore versions
  2. Pulling code from a Git repository
  3. Deploying the solution into a working directory
  4. Rebuilding the downloaded solution
  5. Validating steps during installation
  6. Displaying notification messages during installation

 Steps to installing Sitecore with PowerShell


The script requires a little work to properly setup the Sitecore installation repository, however, once that is completed and configuration changes have been performed, it is smooth sailing from there on –

  1. Download Sitecore PowerShell Deployment Package
  2. Download the Sitecore folder archives from the SDN (make sure to modify the archive to include the Website, Databases, and Data folders to be direct descendants of the archive) and name them using {version}rev{revision}.zip naming convention (ensure to include zeroes, for instance 710rev140130.zip)
  3. Modify versions.xml to include the downloaded versions of Sitecore
  4. Upload the folder with Sitecore archives, versions.xml, and Sitecore license file to a remote location from which they will be downloaded using the script (this allows for multiple developer downloads from a central location; this location will be set in the install.config under BaseStorageUrl setting)
  5. Modify the install.config as follows (check the comments inside the file for detailed setting explanations)
  6. Run the script and make some coffee

*Please note that the script deploys the solution folder directly under Website. In my projects I use Post-Build Events in Visual Studio to copy the binaries and other files to the proper folders.

When you come back Sitecore will be up and ready to go. Depending on the size of the solution to be downloaded from the repository and the internet connection speed, the installation may take as little as three minutes.

This is just a small stab at the PowerShell scripting for Sitecore, there are many more tasks that come into mind right away – the obvious include uninstalling, scalability configuration, live mode enabling, Sitecore hardening, CD configuration, DMS installation…etc. in other words I encourage all Sitecore enthusiasts to use PowerShell for streamlining Sitecore tasks. Please comment with links to any other useful PowerShell scripts, or simply follow this blog for more scripts to come!

Common Issues during Sitecore Installation with PowerShell

  1. Unable to run the script due to tight ExecutionPolicy setting – When this happens simply execute Set-ExecutionPolicy RemoteSigned command in PowerShell run as Administrator
  2. Permission denied message while deploying the solution – make sure that the scrip is executed from PowerShell run as Administrator
  3. “The term ‘install-module’ is not recognized as the name of a cmdlet…” error – this means that PsGet has not been installed yet. Simply execute (new-object Net.WebClient).DownloadString(“http://psget.net/GetPsGet.ps1”) | iex  and then install-module posh-git commands to install it in PowerShell run as an Administrator

That’s it! Happy scripting!

2 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

  • Vasiliy Fomichev
    April 30, 2014 at 7:03 pm

    @seanholmesby:disqus, I use the SIM religiously myself but only for quick testing or the initial setups.

    If we are starting a project though, once the base solution has been setup, I then create a PowerShell script and distribute it to the team, so they can simply run in, go get some coffee in the meantime, and when they are back – the solution is up and ready to rock and roll 🙂

    I haven’t tapped into the SIM’s API yet, but it sounds attractive!

  • Sean Holmesby
    March 15, 2014 at 9:19 pm

    Interesting post.
    I love the automation of everything.

    Personally I prefer to use the Sitecore Instance Manager tool for Sitecore installations, which include a lot of the features you mention (MVC support, Analytics, etc.)

    It also has it’s own API which can be used for scripting, allowing for even more automation than the base program.