无法使用 powershell 重命名计算机

无法使用 powershell 重命名计算机
$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
  • 我禁用了机器上的防火墙。
  • 我跑了enable-PSRemoting -force
  • 我甚至将 GPO 设置为Allow remote server management through WinRM启用 *

我不断得到:

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

为什么要通过远程方式 (invoke-command) 使用具有 -computername 参数的 cmdlet?您是否尝试过直接运行该命令?

相关内容