I am trying to run a script to rename remote computers via PowerShell. The problem I'm running into is that I'm getting the following error:

Rename-Computer : Cannot establish the WMI connection to the computer 'computername' with the following error
Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
At C:\temp\scripts\rename_script\new_rename.ps1:8 char:5
+     Rename-Computer -NewName $Computer.newname -ComputerName $compute ...
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : OperationStopped: (WLA-WS174931:String) [Rename-Computer], InvalidOperationExce
    + FullyQualifiedErrorId : RenameComputerException,Microsoft.PowerShell.Commands.RenameComputerCommand

I am running the command using a domain admin credential from an administrative PowerShell window. I am able to run Get-WMIobject on remote computers successfully. The WMI repository is consistent. I've restarted the WMI service. I can run the command on a local computer with no errors, but trying to run it over the network results in an access denied whether I script it or do it manually. The OS of both target and source systems is Windows 7.

The command I'm using is:

$cred = get-credential
rename-computer -newname newname -computername oldname -domaincredential $cred -restart -passthru -force

I'm a PowerShell/WMI novice, but I feel like I've covered the bases pretty well here. What am I missing?

  • does 'Invoke-Command -computername $computername -scriptblock {hostname}` work? – Colyn1337 Sep 26 '18 at 17:50
  • Fail to rename computer 'oldname' to 'newname' due to the following exception: Access is denied. +CategoryInfo: OperationStopped (oldname:String) [Rename-Computer], InvalidOperationException +FullyQualifiedErrorId: FailToRenameComputer,Microsoft.PowerShell.Commands.RenameComputerCommand +PSComputerName: oldname Sorry, it's not super clear in a comment, but yeah, same issue. – Olylo Sep 28 '18 at 15:19
  • This requires troubleshooting, there's quite a few things that can cause this error. The first thing that comes to mind is that the box is not on the domain. – Colyn1337 Sep 28 '18 at 21:06
  • This is being done to and from PCs joined to the same domain. – Olylo Oct 1 '18 at 15:47
  • If you run it locally does it work? There's a lot of restrictions that can be setup when running commands locally. I also see a discrepancy between what you put in your code as -newname newname and what is listed in the error -NewName $Computer.newname how are you generating $Computer.newname? – Nixphoe Oct 4 '18 at 20:24

You would need to sets of credentials to perform the change in domain environment.

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

This command renames the Srv01 computer to Server001 and then restarts it to make the change effective. It uses the LocalCredential parameter to supply the credentials of a user who has permission to connect to the local computer and the DomainCredential parameter to supply the credentials of a user who has permission to rename computers in the domain. It uses the Force parameter to suppress the confirmation prompt and the PassThru para meter to return the results of the command.

|improve this answer|||||
  • I have a domain account that is a member of all local administrators groups that also has domain renaming privileges. Can I just pass that credential to both parameters (i.e. using a variable and get-credential)? – Olylo Oct 11 '18 at 13:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.