#Change Computer Name
#------------------------------------------------------------------------------------------
Write-Verbose -Message "Changing computer name. Old name: $ComputerName, New name: $NewComputername" -Verbose
rename-computer -computername $ComputerName -newname $NewComputername -domaincredential $Credential -Force
#Restart Computer
#------------------------------------------------------------------------------------------
Write-Verbose -Message "Rebooting $ComputerName. Please wait" -Verbose
Restart-Computer -ComputerName $ComputerName -Force -Wait -Timeout 300
#Test if changing the computername causes the -wait to fail
When the computer is renamed, it has to be rebooted, but once it boots back up it is now using the new name. Is the -wait parameter waiting for the old computer name, then times out? If it is, what is a good way to rename, reboot, wait for the computer to be accessible (WinRM), then continue with the script succesfully?