Manipulating config files with PowerShell


It is a quite common situation when you need to prepare multiple Sitecore servers with different roles. If you take a look a Sitecore documentation you will find a huge amount of tables with configuration files that need to be enabled/disabled.

Going manually through all of them isn’t the most fun task you could do, so I prefer to do this only once. Don’t repeat yourself 🙂

Also, this would be needed for an environment automation work I’m involved in, but this would be a separate set of posts.


First, review configuration for version 8.0 and put it in some readable format.
Then, create PowerShell script to switch configurations and embed into build pipeline (this part is not covered).

Sitecore configuration

Unfortunately, it doesn’t have a nice Excel spreadsheet as 8.1, so I went through various pages on and created my own file: Sitecore 8.0 update 3 configuration checklists.

This file includes:

  • 4 server roles configuration
  • Transforms checklist
  • Security & other configurations

* only SOLR enabled configuration 


The script itself is quite easy: two functions – one to disable files and one to enable them. Functions accept website root as a parameter and a PowerShell hashtable with enabled and disabled file paths arrays (just copy required file paths from excel above)

function Disable-Files($root, $files) {
	$files.disabled |
		ForEach-Object {
			$path = Join-Path $root $_

			dir "$path*" |
				ren -NewName {
					write-host "Disable: $($_.fullname)"
				} -Force

function Enable-Files($root, $files) {
	$files.enabled |
		ForEach-Object {
			$path = Join-Path $root $_

			dir "$path.*" |
				? name -match '(?i)\.disabled|\.example$' |
				ren -newname {
					write-host "Enable: $($_.fullname)"
					$ -replace '(?i)\.disabled|\.example$', ''
				} -Force

$webrootPath = "d:\temp\Sitecore 8.0 rev. 150427\Website\"

$roles = @{
	processing = @{
		enabled = @(
		disabled = @(
			# ...
	cm = @{
		# ...
	cd = @{
		# ...
	# ...

Disable-Files $webrootPath $roles.processing
Enable-Files $webrootPath $roles.processing


After execution you would see following:


We are done – config files extensions changes to .DISABLE where needed (and back)


You could also use CSV format to upload data as it was done in like it was done in @MichaelWest101 tweet, but this was prepared for PowerShell DSC and it’s .psd1 format.

As usual: Share if you like the post. Follow me on twitter @true_shoorik

Manipulating config files with PowerShell

2 thoughts on “Manipulating config files with PowerShell

    1. We trying not to use MSBuild for anything else rather than build. Powershell scripts are portable and usually you do not need to have anything else installed on machine to run them.

      E.g. this one could be delivered via Octopus and run directly on machine where it landed.


Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s