令人困惑的 Powershell 行为

发布于 2024-12-02 23:05:10 字数 808 浏览 2 评论 0 原文

我对远程执行 powershell 命令有点困惑。我有一个名为 ServerA 的测试服务器 (Win 2k8-R2-SP1),它正确启用了 powershell 远程处理。在我的开发机器 (Win 2k8-R2-SP1) 上,我能够正确远程执行 powershell 命令。 但是,当我尝试从名为 ServerB (Win 2k8-R2) 的不同服务器执行相同的命令时,出现以下错误

[ServerA] 连接到远程服务器失败,并显示以下错误消息:客户端无法连接到请求中指定的目的地。验证目标上的服务正在运行并且正在接受请求。请查阅在目标(最常见的是 IIS 或 WinRM)上运行的 WS-Management 服务的日志和文档。 如果目标是 WinRM 服务,请在目标上运行以下命令来分析和配置 WinRM 服务:“winrm Quickconfig”。有关详细信息,请参阅 about_Remote_Troubleshooting 帮助主题。 + 类别信息:OpenError:(:) [],PSRemotingTransportException + FullQualifiedErrorId : PSSessionStateBroken

所有三台机器都在同一个域中。我的困惑是,从我的开发机器上,我完全能够连接到 ServerA 并执行命令。

ServerB 没有 SP1 会产生影响吗?请指教。我使用的域帐户在所有 3 台服务器上都具有管理员权限。

我正在尝试的命令是 Invoke-Command -ComputerName ServerA -ScriptBlock {Get-UICulture}

请帮忙。

谢谢

Am a bit confused w/ remote executing a powershell command. I have a test server (Win 2k8-R2-SP1) called ServerA, which has powershell remoting enabled correctly. From my dev machine (Win 2k8-R2-SP1), am able to remote execure powershell commands correctly.
But, when I try to execute the same command from a different server called ServerB (Win 2k8-R2), I get the following error

[ServerA] Connecting to remote server failed with the following error message : The client cannot connect to the destination specified in the request. Verify that the service on the destination is running and is accepting requests. Consult the logs and documentation for the WS-Management service running on the destination, most commonly IIS or WinRM.
If the destination is the WinRM service, run the following command on the destination to analyze and configure the WinRM service: "winrm quickconfig". For more information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (:) [], PSRemotingTransportException
+ FullyQualifiedErrorId : PSSessionStateBroken

All three machines are in the same domain. My confusion is that from my dev machine, I am perfectly able to connect to ServerA and execute the command.

Will the fact that ServerB does not have SP1, make a difference? Please advise. I am using the same domain account which has admin rights on all 3 servers.

And the command that I am trying is
Invoke-Command -ComputerName ServerA -ScriptBlock {Get-UICulture}.

Please help.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

三寸金莲 2024-12-09 23:05:10

从 ServerB 运行 winrm QuickconfigEnable-PSRemoting -force

使用 get-service winrm

http://technet.microsoft 验证服务是否正在运行。 com/en-us/magazine/ff700227.aspx

另外,从本地开发箱运行此命令:

Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*" -Force

Run winrm quickconfig or Enable-PSRemoting -force from ServerB.

Verify service is running with get-service winrm

http://technet.microsoft.com/en-us/magazine/ff700227.aspx

Also, run this from your local dev box:

Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*" -Force
初与友歌 2024-12-09 23:05:10

我也遇到过同样的问题,在一台过去用于远程 powershell 的机器上。就我而言,解决方案是清除安全日志。它已满,我相信这会阻止 powershell 建立适当的安全连接。

I've had this same problem as well, on a machine that was working for remote powershell in the past. In my case the solution was to clear the Security Log. It was full, and I believe this was preventing powershell from making a proper secure connection.

眼泪也成诗 2024-12-09 23:05:10

以下解决了我的问题:

您必须清空 iplisten 列表,可以使用以下 CMD 命令进行检查:

netsh http show iplist

或者如果有任何其他地址,则将环回地址添加到其中:

netsh http add iplisten 127.0.0.1

The following fixed my problem:

You either have to empty your iplisten list which can be checked using the following CMD command:

netsh http show iplist

or to add the loop back address to it if there is any other addresses:

netsh http add iplisten 127.0.0.1
雪若未夕 2024-12-09 23:05:10

我遇到了同样的问题并通过以下方式解决了。运行

winrm quickconfig

返回以下错误。

winrm : WSManFault
At line:1 char:1
+ winrm quickconfig
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (WSManFault:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

    Message
        ProviderFault
            WSManFault
                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. 
Error number:  -2144108183 0x80338169
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. 

就我而言,这是我机器上运行的虚拟机管理程序服务的虚拟网卡。当我将其更改为 Private 后,winrm Quickconfig 运行时没有错误。我仍然在连接到某些机器时遇到问题,并遇到与此线程中描述的相同的故障。为了解决这个问题,我检查并启动了 winrm 服务(它已停止)。

get-service -ComputerName computer -Name winrm

Status   Name               DisplayName                           
------   ----               -----------                           
Stopped  winrm              Windows Remote Management (WS-Manag...



get-service -ComputerName computer -Name winrm | Start-Service

I was having this same issue and resolved in the following way. Running

winrm quickconfig

returned the below error.

winrm : WSManFault
At line:1 char:1
+ winrm quickconfig
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (WSManFault:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

    Message
        ProviderFault
            WSManFault
                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. 
Error number:  -2144108183 0x80338169
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. 

In my case, this was a virtual NIC for a hypervisor service I was running on my machine. Once I changed this to Private, winrm quickconfig ran without error. I still had issues connecting to some machines and getting the same failure as described in this thread. To resolve, I checked for and started the winrm service where it was stopped.

get-service -ComputerName computer -Name winrm

Status   Name               DisplayName                           
------   ----               -----------                           
Stopped  winrm              Windows Remote Management (WS-Manag...



get-service -ComputerName computer -Name winrm | Start-Service
素罗衫 2024-12-09 23:05:10

为了避免在您管理的每台服务器上启用 WinRM,您可以运行此批处理脚本:

要求:

用法:EnablePSRemoting.bat PC 。TXT

@echo off
for /f %%f in (%1) do (
  psexec.exe \\%%f -accepteula -h -d -s powershell.exe "enable-psremoting -force"
  echo Enabled on %%f
)

To save having to enable WinRM on every single server you manage, you can run this batch script:

Requirements:

Usage: EnablePSRemoting.bat PCs.txt

@echo off
for /f %%f in (%1) do (
  psexec.exe \\%%f -accepteula -h -d -s powershell.exe "enable-psremoting -force"
  echo Enabled on %%f
)
月竹挽风 2024-12-09 23:05:10

我已经寻找答案好几天了,我发现了问题所在;

似乎未安装 IIS 7 .NET Extensibility 组件导致此问题。我们有一台 2012 R2 Exchange 2010 服务器;

https://technet.microsoft.com/en -us/library/dd421841(v=exchg.80).aspx

我通过在 powershell 中输入它来安装它;

请参阅此处了解 Exchange 2010 的先决条件。

https://technet .microsoft.com/en-us/library/bb691354(v=exchg.141)

我们的这台Exchange服务器只有邮箱角色,其他仍然是CAS和HUB传输;

所以我们需要这个命令;

添加 WindowsFeature NET 框架功能、RSAT 集群、Web 管理控制台、WAS 进程模型、Web 基本身份验证、Web-Lgcy-管理控制台、Web 元数据库、Web-Net-Ext、Web -Server,Web-Windows-Auth -Restart

Web-Net-Ext 部分安装了 IIS 7.NET 扩展性组件。
无需重新启动。

只是我的 2 美分,也许这对其他人有帮助:-)

I have been looking for the answer for days and I found the issue;

It seems that the IIS 7 .NET Extensibility component was not installed causing this issue. We have a 2012 R2 Exchange 2010 server;

https://technet.microsoft.com/en-us/library/dd421841(v=exchg.80).aspx

I installed it by entering this in powershell;

See here the prerequisites for Exchange 2010.

https://technet.microsoft.com/en-us/library/bb691354(v=exchg.141)

This Exchange server of ours has only the mailbox role, the other is still CAS and HUB transport;

So we need this command;

Add-WindowsFeature NET-Framework-Features,RSAT-Clustering,Web-Mgmt-Console,WAS-Process-Model,Web-Basic-Auth,Web-Lgcy-Mgmt-Console,Web-Metabase,Web-Net-Ext,Web-Server,Web-Windows-Auth -Restart

The part of Web-Net-Ext installed the IIS 7.NET Extensibility component.
No need to restart.

Just my 2 cents, maybe this helps someone else :-)

独自唱情﹋歌 2024-12-09 23:05:10

就我而言,WinRM 配置正确。这是我用来远程启用它的方法:

$x=Get-WmiObject -ComputerName "<computer name>" -Namespace "root\cimv2" -Class "Win32_Process" -List
$x.Create('C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command {Enable-PSRemoting}"',$null,$null)

In my case, WinRM was not configured correctly. This is what I used to enable it remotely:

$x=Get-WmiObject -ComputerName "<computer name>" -Namespace "root\cimv2" -Class "Win32_Process" -List
$x.Create('C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "& C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command {Enable-PSRemoting}"',$null,$null)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文