Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Script to Rename Computer without Reboot
$ComputerName = "New Name"
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 "HKU:\.Default\Software\Microsoft\Windows Media\WMSDK\General" -name "Computername" -value $ComputerName
@artemyarulin

This comment has been minimized.

Copy link

commented Aug 10, 2014

Thank you very much for the script!

@cotarelo2

This comment has been minimized.

Copy link

commented Jul 28, 2017

Thank you for the script! You could add

-join ((65..90) + (97..122) | Get-Random -Count 5 | % {[char]$_})

So the computer name is generated randomly

It would be awesome if one could access the virtual machine name from vmware

@lollenka

This comment has been minimized.

Copy link

commented Aug 4, 2017

I'm not too good at it. Could you please tell me, after I replace the computer names here with the ones I need, what do I do with this script? Do I save it under some specific name and paste into system files? I have Win10. Please.

@TheBoroer

This comment has been minimized.

Copy link

commented Sep 18, 2017

@lollenka This is a powershell script. You can just open a powershell window and then paste this in

@audioscavenger

This comment has been minimized.

Copy link

commented Apr 17, 2018

you need to be admin AND enable your Your Execution Policy as described here

@discentem

This comment has been minimized.

Copy link

commented Apr 23, 2018

This seems to cause Not enough storage is available to complete this operation for just about every command I try to run after editing the registry in this way on Windows Server 2008.

@thangvc91

This comment has been minimized.

Copy link

commented Aug 2, 2018

Hi Cotarelo ,
I would like to ask you about you comment on July 27 2017 , could you please help a full code after adding the "-join ((65..90) + (97..122) | Get-Random -Count 5 | % {[char]$_})".I don't know where i can put the code. Sorry for my bad question ?

@uluQulu

This comment has been minimized.

Copy link

commented Dec 21, 2018

Thanks @timnew, worked flawlessly on Windows 7 Home Basic.

I just also had to run,
Set-ExecutionPolicy RemoteSigned
at C:\Windows\SysWOW64\WindowsPowerShell\v1.0\ powershell.exe as Administrator (thanks to Glen Little).

@fragtion

This comment has been minimized.

Copy link

commented Jul 30, 2019

Worked great. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.