Process exited with code 255 when running on command prompt through TeamCity

The following command

@Set "installed_version=" & @(FOR /F %a IN ('curl 192.168.1.151:5000/getversion') DO @SET installed_version=%a)

is failing when running on a Windows agent in Teamcity with error

) was unexpected at this time. Process exited with code 255

However, the same command runs smoothly when running on a command prompt on my local Windows 10 machine. The teamcity agent is a Windows Server 2008 R2, version 6.1.

What am I doing wrong?