Rename remote computers with Powershell

Quickly rename computer objects in your domain with ease

Wed, 31 Oct 2018

I was stuck having to use LogMeIn or walking over to workstations to change computer names before I found this neat little trick. This trick only works for computers joined to a domain.

Command

Open up a powershell instance and paste the command below.

  • Computer-Name = target computer name
  • NewName = new name for the target computer
  • LocalCredential = local account on computer with administrative access
  • DomainCredential = domain account with access to change computer names
  • Force = Runs the command without the confirmation from local user
  • PassThru = returns results of the command. You can forgo this command, doing so will not return any success/failure results
Rename-Computer -ComputerName "Srv01" -NewName "Server001" -LocalCredential Srv01\Admin01 -DomainCredential Domain01\Admin01 -Force -PassThru

In the event that you end up getting this error

Rename-Computer : Cannot establish the WMI connection to the computer ‘priorauthdes’ with the following error message: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).

You can start a remote session to the local computer and run the Rename-Computer command. We will be using Enter-PSSession cmdlet to achieve this. The following command will start a remote powershell session with the computer “Srv01”.

enter-possession “Srv01” -credential Domain01\Admin01

Now that we are logged in “locally” to the target computer we can run the Rename-Computer cmdlet again. We want to make some slight changes before running it since we no longer need the target computer name.

Rename-Computer -NewName "Server001" -LocalCredential Srv01\Admin01 -DomainCredential Domain01\Admin01 -Force -PassThru

After a restart, the computer name change will take effect.

Automatic Restart

If you know that there is currently no one using the target computer, you can add -Restart to the cmdlet to have the computer automatically restart if the cmdlet went through successfully.

Buy Me A CoffeeDigitalOcean Referral Badge
Loading...
Edward Beazer

Edward Beazer - I just like to build shit. Sometimes I get stuck for hours, even days while trying to figure out how to solve an issue or implement a new feature. Hope my tips and tutorials can save you some time.

DigitalOcean Referral Badge