-
-
Save uchagani/9bcd9ce8d8f7d9cee727 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function RenameComputer($ComputerName) | |
{ | |
$computer = Get-WmiObject -Class Win32_ComputerSystem | |
$computer.rename("$ComputerName") | |
Remove-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "Hostname" | |
Remove-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "NV Hostname" | |
New-PSDrive -name HKU -PSProvider "Registry" -Root "HKEY_USERS" | |
Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\Computername\Computername" -name "Computername" -value $ComputerName | |
Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Control\Computername\ActiveComputername" -name "Computername" -value $ComputerName | |
Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "Hostname" -value $ComputerName | |
Set-ItemProperty -path "HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters" -name "NV Hostname" -value $ComputerName | |
Set-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "AltDefaultDomainName" -value $ComputerName | |
Set-ItemProperty -path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" -name "DefaultDomainName" -value $ComputerName | |
Set-ItemProperty -path "HKCU:\Volatile Environment" -name "LOGONSERVER" -value $ComputerName | |
[Environment]::SetEnvironmentVariable("COMPUTERNAME", "$ComputerName", "User") | |
} |
This doesn't seem to be doing anything:
$computer = Get-WmiObject -Class Win32_ComputerSystem
$computer.rename("$ComputerName")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Weirdly this isn't working on all systems. Digging into it now.