Get-Service 失败,但 Invoke-Command {Get-Service} 成功

问题描述 投票:0回答:1

我尝试在台式计算机上运行一系列 PowerSHell 命令,这些命令连接到其中一台公司服务器并检查那里的服务状态。我正在 PowerShell ISE 上执行运行方式并使用远程服务器管理员组中的帐户登录。该命令失败:

Get-Service -ComputerName SRV-TSTD123 -DisplayName *Dynamic*
Microsoft.PowerShell.Management\Get-Service : Cannot open Service Control Manager on computer 'SRV-TSTD123'. This operation might require other 
    privileges.
    At line:1 char:1
    + Microsoft.PowerShell.Management\Get-Service -ComputerName SRV-TSTD123 ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [Get-Service], InvalidOperationException
        + FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetServiceCommand

最奇怪的是这个命令有效:

invoke-command -computername srv-tstd123 -scriptblock {powershell Get-Service -DisplayName *Dynamic* }

Status   Name               DisplayName                           
------   ----               -----------                           
Running  DynGP18eConnect    eConnect for Microsoft Dynamics GP ...
Running  DynGPWebService    Microsoft Dynamics GP Service Host    
Stopped  eConnect_Incomi... eConnect Incoming Service for Micro...
Stopped  econnect_outgoi... eConnect Outgoing Service for Micro...
Running  PostMasterService  Post Master Enterprise for Dynamics GP

此命令是第三方提供的脚本的一部分,因此我更愿意解决这种不一致行为的根本原因,而不是对脚本进行十几个更改。知道为什么行为如此不一致吗?

powershell invoke-command
1个回答
0
投票

我最终让我办公室的整个基础设施团队参与进来,我们通过稍微放松防火墙规则来解决这个问题。根据我的防火墙管理员的说法:防火墙规则要求允许 ms 服务控制器。

此问题现已解决。谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.