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

标签 powershell powershell-remoting remoting invoke-command .net-remoting

我正在尝试在台式计算机上运行一系列 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

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

最佳答案

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

此问题现已解决。谢谢。

关于powershell - Get-Service 失败,但 Invoke-Command {Get-Service} 成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/77433505/

相关文章:

powershell - Windows 10 上的 docker-machine - "You must have a copy of the scp binary locally to use the scp feature"

wcf - 企业服务总线和消息代理

powershell - 在远程Windows Server上创建本地用户并添加到管理员组

powershell - 如何在Powershell上运行长时间运行的程序的远程程序

.net - 运行 Visual Studio 2010 实例并以编程方式附加到进程?

c# - 远程应用程序期间出现 ArgumentNullException

powershell - 如何在 PowerShell 中传递可选参数?

powershell - 如何使用 Powershell 从任务栏取消固定 "Library"文件夹?

sql-server - SQL Server SMO,应该在每次修改内容时调用刷新吗?

powershell - 文件操作因 New-PSSession 失败