The reason this fails in a PowerShell step of SQL Agent is due to the tokens with Agent jobs. A token, when used in Agent job, is wrapped using "$()", so anything within that is picked up by SQL Agent as a token and it will try to resolve it as one. These are used differently in PowerShell and just don't mix well when you try to use them in a SQL Agent PowerShell job step.
It is best to use a CmdExec step in SQL Agent as it will give you the most consistent experience to running scripts in normal PowerShell or PowerShell ISE.
Shawn Melton
Twitter: @wsmelton
Blog: wsmelton.github.com
Github: wsmelton