So turns out the code does work.

Install this first to get powershell up to version 3

https://www.microsoft.com/en-ca/download/details.aspx?id=40855