When I create a fixlet for this, I put in a domain service account since the local system account wouldn’t have permissions within AD to change the name:
// Disable wow64 redirection on x64 OSes
action uses wow64 redirection {not x64 of operating system}
action parameter query "ServerName" with description "Please enter the New Server Name" with default value "New Server Name"
delete __createfile
// CREATEFILE
createfile until END_OF_FILE
$bfuser = '{parameter "secret" of action}'
$bfpass = '{parameter "secret2" of action}'
$password = $bfpass | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PsCredential -ArgumentList $bfuser, $Password
Rename-Computer -NewName "{parameter "ServerName"}" -DomainCredential $Credential -Force
END_OF_FILE
delete powershell.ps1
move __createfile powershell.ps1
waithidden { pathname of file ((it as string) of value "Path" of key "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" of native registry) } -ExecutionPolicy Bypass -File powershell.ps1