This is my first week back after two months off taking care of my new twin girls, and my new year’s resolution this year was to blog more, so I’m going to attempt to create a series of “Today I Learned” posts. They will consist of short commentary on some sort of technical thing I did or learned about during the week. The first one will be on our team’s Powershell script that we use to set up our development environment.
Before we had our powershell script, setting up our dev environment was a nightmare – new hires would spend up to a week working on it, and if anything was ever added / changed / removed, the entire team was down for at least a day. Given our codebase’s dependency on a bunch of other things (other teams’ projects, network setup, development servers, etc.), we were losing a considerable amount of time.
So, enter the Powershell script. Using Powershell, we’re able to automate a good portion of our dev env setup and maintenance – here’s a few examples of what we’ve been able to set up.
Adding things to your environment’s path variable
1 2 3
Use this to add things to your path variable. We do this mostly so we don’t have to include full absolute paths later on in our script to execute things like MSBuild.
Creating websites, applications, virtual directories in IIS
This requires the inclusion of a script called Carbon, you can find it here
1 2 3 4
Carbon is awesome, and one of the things we use most in our script. Among other things, it allows you to manipulate your IIS configuration by adding / editing / removing websites, applications, virtual directories, and application pools.
Command line operations
1 2 3
You can straight up call any command line operation (here we’re calling tf.exe to reference TFS source control), and have the output saved as an array variable. It’s a bit hacky here, relying on the 3rd output line to give us the workspace info we need, but command line output doesn’t change often and it works :)
Combining all these things together, our script sets up 5 different websites in IIS with their required app pools, virtual directories, and security settings, gets the latest version of external dependencies from TFS, gets our latest code from Github, builds it all using MSBuild, and also deploys our database changes with MSBuild and SQL Database Projects. Epic win.