繁体   English   中英

尝试远程终止进程时发生PowerShell / WinRM错误

[英]PowerShell / WinRM error while trying to kill a process remotely

我想使用以下命令在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设置winrm / config / client'@ {TrustedHosts =“ sag35”}'

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

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

添加另外的什么Trondh写的WinRM需要在源..我没有WinRM的质量控制, 在这篇文章中提到我现在在的WinRM源和目标,我可以做WinRM的ID(我的理解是本地平)。 我还设法使Trustedhosts行适用于每个comp,例如winrm set winrm winrm set winrm/config/client '@{TrustedHosts="compA"}'

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

我跑了: reg add HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f ,如此此处所述,但不需要,因为该值已在注册表中,并且端口5985用于http已打开,并通过我局域网内那些计算机上的Windows 7防火墙。 端口5986(用于HTTPS)已关闭,但我可能只需要5985 / http。 我了解此端口是自动设置的,并且可以访问。

这篇technet文章建议了一些测试,例如将winrm id ping到ping,以及使用-r进行远程ping。

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

Error number:  -2147024891 0x80070005  
Access is denied.  

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

$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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM