But if I log into the remote desktop of the team city agent server and do all these things at the command prompt, then they all work without a problem and the sites shut down gracefully.

Something about the way Team City launches these commands in the build steps....
_________________________
Tony Fabris