I must be doing something differently than what was asked and answered here because the solution does not appear to be working for me: TeamCity, passing an id generated in o
I think you have an extra "\" in there. Try removing that and add double quotes around it and it should work.
"##teamcity[setParameter name='env.TEST' value='test']"
If it doesn't work try using Powershell runner type as I'm using that for setting it and it works.