Changing Windows hostnames via the command line»

We have various automation scripts that need to change machine hostnames on Windows (sometimes via SSH, sometimes via batch files). This is actually pretty simple to do, though it took awhile to track down the correct command:

wmic computersystem where name="$COMPUTERNAME" call rename name="newname"
    shutdown /r /d p:2:2