I also needed the computer name to match our naming convention - in this case it had to begin with the letters zzz.
$ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem
$ComputerName = gc env:computername
If ($ComputerName -notmatch "ZZZ") {
write-host -foregroundcolor Red "Existing Computer Name: $ComputerName"
write-host -foregroundcolor Red "You need to change the name so it doesn't clash with others"
$NewName = read-host -prompt "New name (ZZZ will be prepended automatically)"
$ComputerInfo.Rename("slops"+$NewName)
Restart-Computer
}
The script below runs in powershell and prompts for the new computer name, prepends the word "zzz" and then renames and reboots the machine.
I put this command in a scheduled task that runs on login.
I put this command in a scheduled task that runs on login.
$ComputerInfo = Get-WmiObject -Class Win32_ComputerSystem
$ComputerName = gc env:computername
If ($ComputerName -notmatch "ZZZ") {
write-host -foregroundcolor Red "Existing Computer Name: $ComputerName"
write-host -foregroundcolor Red "You need to change the name so it doesn't clash with others"
$NewName = read-host -prompt "New name (ZZZ will be prepended automatically)"
$ComputerInfo.Rename("slops"+$NewName)
Restart-Computer
}