I know some might consider this heretical, but have you considered Powershell for these type of scripts?