Automated Machine Builds with PowerShell and AutoIT

I have been using PowerShell recently to create scripted builds for virtual machines. This method provides some benefits over imaging.

  • A single base image per OS can be used
  • Applications which have issues with imaging can be easily installed such as SQL Server, BizTalk, Exchange, Etc.
  • Scripted installs can be changed or updated easier than images
  • Additional configuration changes such as registry settings and/or configuration files can be easily done

One challenge I faced with this process was automating the installation of applications which do not have unattended install capabilities.

A great tool I found for this was AutoIT. It provides a method to script the windows GUI and enables automating those installs. AutoIT consists of a COM object, scripting language, editor, compiler, and a cool window info tool. I will not get into the details of AutoIT here it has good documentation. I found PowerShell to be much stronger at the scripting part, but the COM object provides excellent window control functionality to PowerShell. The window info tool that comes with AutoIT is also very handy. Here is a simple example:

To run the code above you will need to install AutoIT or just register the AutoItX.dll COM object. The code will launch notepad and type “This is a test”. While this is a pretty useless example it shows the basic purpose of AutoIT and how it is used from PowerShell.

The next piece I looked at was creating a function library to make it easy to use AutoIT from PowerShell.

Example: AutoIT PowerShell function library

Then using the functions from the library above I created application installation functions for various packages.

Example: PowerShell Application Installation Function

Using the method above I created a library of PowerShell installation functions to be called from automated build scripts.

This seems to be working pretty well so far and it allows automated builds to be scripted quickly. PowerShell and AutoIT work well together, the AutoIT COM object provides excellent GUI control and PowerShell provides strong scripting and debugging features.

Best Regards,