Learn about Windows PowerShell
Summary: Use Windows PowerShell to rename a newly created computer.
How can I use Windows PowerShell to rename a computer if I don’t know the machine name?
Use the Rename-Computer cmdlet and the built in HOSTNAME command, then reboot the computer. For example, to rename a computer to called MININT-123 to CONTOSO-FS:
RENAME-COMPUTER –computername MININT-123 –newname CONTOSO-FS
If I am not wrong, the system requires a reboot after rename to take effect. I am not sure. I tried
$PC = Get-WmiObject -Class Win32_ComputerSystem
You are absolutely correct. A reboot of the machine is required.
Now to rename the computer locally if you don't know it's name in one line.
RENAME-COMPUTER -computer name (hostname) -newname CONTOSO-FS; RESTART-COMPUTER -force
More correctly a restart is ALWAYS required after a computer is renamed, even with WMI
Yes, restart is required to effect the name change. The restart command can also be included here.
Nice sample, thanks for sharing.
On Windows 8 and above, the Rename-Computer function includes a -restart parameter so it is not necessary to also use the Restart-Computer function.
Hi All, thanks for sharing tips. I just installed Windows 8.1 - PowerShell Rocks :)
@Sean Kearney - Your code has typo
RENAME-COMPUTER -computername (hostname) -newname CONTOSO-FS; RESTART-COMPUTER -force
ComputerName "No Space"
This can be done like below
Rename-Computer -NewName PowerShell -DomainCredential Domain01\Admin01 -Restart
By default - ComputerName is localhost