This post is a quick reference sheet for some useful PowerShell scripts I've used in the past. These scripts are all designed to help you to pragmatically update your config files using Powershell. I fully admit the contents of this post won't be for every reader.

Before using any of these, I would recommend reading this post first, 4 Points You Should Consider Before Using Octopus With Episerver.

As the first port of call, I recommend using web config transforms. Some clients may have non-standard infrastructure set-up, crazy security processes, and God knows what else. In most of the snippets below, these powershell snippets are being run by the build server before Octopus/the deployment process is run. In most of the snippets, I'm getting a config file from the build server, replacing the value with an Octopus variable name only. This code isn't injecting config values directly, however, you could change the Octopus variable to use a pre-defined value.. it's all up to you. In this set-up when Octopus gets triggered, it will then replace the variables with whatever's set in your variable.

In this set-up you're effectively doing two transforms. one to programmatically add the Octopus variables into the config files and using Octopus afterward to do the transforms on the variables themselves. A bit long winded I'll happily admit and I wouldn't class this process as 'standard', or 'good practice'. One benefit of this approach, however, is that IT administrators and people who may not have Visual Studio installed can work on your build process and procedure.

Load and Save A Config File

This first snippet will be the starting point for most of the other snippets below. This snippet shows how you can load a config file with PowerShell and then save it afterward.

Update An AppSetting

This one will find an app settings in a seperate app settings config file and change the 'EPi.DebugView.Enabled' setting to true.

Change The Episerver Log File Location

Change The App Data Folder Location

Update All Rewrite Rules Url

This script will update any of your URL rewrite rules Url properties with an Octopus variable. This came in useful on a project that required a reverse proxy to handle legacy resources.

Update Redis In Your ConnectionString

This script will set your Redis session state, to use Octopus variables instead.

Change The Episerver Indexing Service URL

As the name suggests, this will update the baseUri property for the Episerver indexing service, to replace it with an Octopus variable.

Update The Episerver License File To Use An Octopus Variable