Anything related to windows command line or automation is flimsy and you never get the same results. Administering windows build environment makes me want to cry.
Have you tried powershell? I haven't used it in a while, but it was straightforward to automate stuff while being in complete control of what was happening. The object oriented aspect of it lent itself very well to object introspection and seemed pretty intuitive.