Rewrite to work on Powershell 2