4
$script = { Rename-Computer -ComputerName "ADMINIS-ID1PS7V" -NewName "SERVER1" }
$computerName = "ADMINIS-ID1PS7V"
$username = "Administrator"
$pw = "123!@#qaZ"

# Create Credentials
$securepw = ConvertTo-SecureString $pw -asplaintext -force
$cred = new-object -typename System.Management.Automation.PSCredential -argument $username, $securepw

# Create and use session
$session = New-PSSession -credential $cred -ComputerName $computerName
Invoke-Command -Session $session -ScriptBlock $script
Remove-PSSession $session
  • I disabled the firewall on the machine.
  • I ran enable-PSRemoting -force
  • I even set the GPO with Allow remote server management through WinRM to enabled with *

I keep getting:

Fail to rename computer 'ADMINIS-ID1PS7V' to 'SERVER1' due to the following exception: Access is denied.
    + CategoryInfo          : OperationStopped: (ADMINIS-ID1PS7V:String) [Rename-Computer], InvalidOperationException
    + FullyQualifiedErrorId : FailToRenameComputer,Microsoft.PowerShell.Commands.RenameComputerCommand
    + PSComputerName        : ADMINIS-ID1PS7V

1 Answer 1

4

Why are you remoting (invoke-command) to use a cmdlet which has a -computername parameter? Have you tried running the command directly?

2
  • That worked. Silly me. Not sure why I was using that on invoke. I just was thinking anything having to be done remotely needed to be in the invoke when invoke is for executing commands locally. If I am correct?
    – Jason
    Jan 4, 2015 at 4:01
  • 1
    Generally, you don't use remoting with cmdlets that include a -computername parameter. To do that you'd need to double-hop, which is not enabled by default. Jan 4, 2015 at 4:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .