使用PowerShell在远程计算机上执行命令

时间:2018-08-21 17:02:07

标签: powershell powershell-remoting invoke-command

我尝试使用PowerShell(以管理员身份运行)在远程计算机上执行一个简单的命令。

Invoke-Command -ComputerName xxxxx -Credential xxx -ScriptBlock{notepad}

但是我有以下问题:

[computer name] Connecting to remote server  failed with
the following error message : Access is denied. For more information,
see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (:String) [], PSRemotingTransportException
    + FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken

在此之前:

  1. 我通过以下方式更改了两台计算机上的策略:

    Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy Unrestricted
    
  2. 并且我启用了在远程计算机上运行PowerShell命令的功能:

    Enable-PSRemoting -Force
    

但是当我在远程计算机上执行Enable-PSRemoting -Force时,出现以下错误:

Set-WSManQuickConfig : <f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2150859113" Machine="localhost">
<f:Message>
<f:ProviderFault provider="Config provider" path="%systemroot%\system32\WsmSvc.dll">
<f:WSManFault xmlns:f="http://schemas.microsoft.com/wbem/wsman/1/wsmanfault" Code="2150859113" Machine="xxxxxx">
<f:Message>
WinRM firewall exception will not work since one of the network connection
types on this machine is set to Public. Change the network connection type
to either Domain or Private and try again.
</f:Message>
</f:WSManFault>
</f:ProviderFault>
</f:Message>
</f:WSManFault>
At line:116 char:17
+                 Set-WSManQuickConfig -force
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Set-WSManQuickConfig], InvalidOperationException
    + FullyQualifiedErrorId : WsManError,Microsoft.WSMan.Management.SetWSManQuickConfigCommand

0 个答案:

没有答案