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,

Dave

Leave a Reply

Your email address will not be published. Required fields are marked *

4 comments

  1. trwagner1 says:

    Superb Dave! Many kudos!

  2. I’m glad it see I’m not the only one who’s has discovered The advantages of working with 2 automation languages. But I does open a security hole.

    For instance, and I have go this to work but I won’t list the exact steps.
    $AutoIT.Send(“Set-ExecutionPolicy Unrestricted”)

    Welcome To the Darkside of the PoSH! Muhaha!!

  3. Gyz says:

    Hi, thx for this informative blogpost. For the moment I’m struggling creating a GUI from scratch from within Powershell. Do you know it is possible to not only control but also create new GUI interface with Powershell and AutoIT? Many thx

  4. John says:

    Do you run your scripts manually after imaging a system or are you putting them into the startup folder