WMI E_ACCESSDENIED errors when attempting to remotely rename computer via PowerShell


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?

asked on Server Fault Sep 25, 2018 by Olylo

1 Answer


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.

answered on Server Fault Oct 5, 2018 by Kirill Pashkov

User contributions licensed under CC BY-SA 3.0