尝试远程终止进程时出现PowerShell / WinRM错误

时间:2014-01-02 11:41:46

标签: powershell

我想使用

在powershell中远程杀死进程

invoke-command -cn computername -script { stop-process name }

我确保目标计算机上的网络未设置为公共,我设法在目标上运行enable-psremoting。

现在尝试在源

运行Invoke-Command ...

但是我遇到了一些错误 PS C:\Users\username> invoke-command -cn sag35 -script { stop-process name } [sag35] Connecting to remote server failed with the following error message : The WinRM client cannot process the request. If the authentication scheme is different from Kerberos, or if the client computer is not joined to a domain, then HTTPS transport must be used or the destination machine must be added to the TrustedHosts configuration setting. Use winrm.cmd to configure TrustedHosts. Note that computers in the TrustedHosts list might not be authenticated. You can get more information about that by running the following command: winrm help config. For more information, see the about_Remote_Troubleshooting Help topic. + CategoryInfo : OpenError: (:) [], PSRemotingTransportException + FullyQualifiedErrorId : PSSessionStateBroken PS C:\Users\username>

我查看了winrm.cmd并添加了一个可信主机

然后我很荣幸这个相当重复的错误消息

`PS C:\ Users \ username> winrm set winrm / config / client'@ {TrustedHosts =“sag35”}'

  

WSManFault
      Message =客户端无法连接到请求中指定的目标。验证目标上的服务是否正在运行并且正在接受请求。查阅目标上运行的WS-Management服务的日志和文档,最常见的是IIS或WinRM。如果目标是WinRM服务,请在目标上运行以下命令以分析和配置WinRM服务:“winrm quickconfig”。

     

错误号:-2144108526 0x80338012
  客户端无法连接到请求中指定的目标。验证目标上的服务是否正在运行并且正在接受请求。查阅目标上运行的WS-Management服务的日志和文档,最常见的是IIS或WinRM。如果目标是WinRM服务,请在目标上运行以下命令以分析和配置WinRM服务:“winrm quickconfig”。
  PS C:\ Users \ username>`

ADDED 继Trondh写的关于在源头需要winrm的内容..我做了winrm qc,mentioned in this article我现在在源码和目录中有winrm,我可以做winrm id(我理解的是本地ping)。 我还设法让trustedhosts行为每个comp工作,例如 winrm set winrm/config/client '@{TrustedHosts="compA"}'

虽然是错误..当我win id -r:compA(来自compB)或win id -r:compB(来自compA)时。我得到相同的错误,无论哪个comp,它都是一个管理PowerShell提示符。

我按照herehere运行了reg add HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f,但没有必要,因为该值已经在注册表中,并且http的端口5985已打开并且通过Windows 7防火墙打开我局域网内的那些电脑。端口5986(用于HTTPS)已关闭,但我可能只需要5985 / http。我知道这个端口是自动设置的,我可以看到它是可访问的。

this technet article建议使用winrm id等一些测试进行ping操作,并使用-r进行远程ping操作。

PS C:\Windows\system32> winrm id -r:compB  
WSManFault  
    Message = Access is denied.  

Error number:  -2147024891 0x80070005  
Access is denied.  

2 个答案:

答案 0 :(得分:3)

您可能需要指定备用凭据,因为两个系统都是工作组成员(不是域成员)。

$Cred = Get-Credential;
Invoke-Command -ComputerName PC01 -Credential $Cred -ScriptBlock { Get-Process; };

以下是WinRM的一些常规故障排除提示:

  1. 确保WinRM服务在客户端和目标系统上运行:Get-Service -Name winrm;
  2. 确保适当的TCP端口正在侦听目标系统(HTTP = 5985; HTTPS = 5986)(使用netstat -aon;
  3. 确保客户端可以访问目标系统上的端口(http://www.nmap.org):nmap -p5985,5986 server01.contoso.com
  4. 确保目标上存在默认的PowerShell会话配置:Get-PSSessionConfiguration
  5. 确保您的用户帐户具有对目标系统的管理访问权限
  6. 确保DNS正确解析到目标系统的IP地址:Resolve-DnsName -Name server01.contoso.com

答案 1 :(得分:0)

您需要先在本地计算机上启动WinRM服务,然后才能编辑winrm属性。

相关问题