What is critical about the server name?
Remember the rule that ALL SIDs are unique, and it applies to system names too. If this was not the case, turning off server of "name1," then renaming another server to "name1" would automatically make it replace the original "name1" in the domain....just does not work that way, each machine has a unique SID.
If you restore the original server to the new server platform from backups, however, it will work to replace the first system in the domain. The original system, however, must be removed totally from the domain to avoid conflicts.
Perhaps you can use the netsh (netsh.exe)utility to run your script?
David