Saturday, August 01, 2015

PowerShell Quick Tips: Rename a computer

Rename local computer to W8M1 and restart
PS D:\> Rename-Computer -NewName W8M1 -Restart
The above command works with Powershell 3.0. For Powershell 2.0, below can be used on an elevated privileges.
PS D:\> $computer = Get-WmiObject Win32_ComputerSystem -ComputerName <old_name>
PS D:\> $computer.Rename("<new_name>")
PS D:\> $os = Get-WmiObject Win32_OperatingSystem
PS D:\> $os.psbase.Scope.Options.EnablePrivileges = $true
PS D:\> $os.Reboot()

Using WMIC to rename a computer
D:\> WMIC ComputerSystem where Name="%computername%" call Rename Name=NewName


No comments: