Updated to work on Powershell 2 and 4.