【问题标题】:PowerShell output different between remote (invoke-command) and local commands远程(调用命令)和本地命令之间的 PowerShell 输出不同
【发布时间】:2018-05-16 11:31:17
【问题描述】:

我已经查看了 Stack Overflow 上的这个问题,但没有找到。到目前为止,我还没有运气搜索过互联网。到目前为止,我找到的答案并没有解决我在从同一服务器的两个不同位置运行的同一命令中看到的差异。也许我没有使用正确的搜索参数。

我的问题:

PowerShell 命令在使用远程调用命令与在本地运行命令时显示不同的输出。我见过几次。

对于本例,运行远程调用命令的服务器运行的是 PS 4 版本的 Windows Server 2012。

正在测试的服务器正在运行带有 PS 2 版本的 Windows Server 2008 R2。

我使用域管理员登录名登录到两台服务器。

====
**Notice Version shows 1.0.0.0 when using remote command.

2012 v4:

(我尝试通过管道格式化表格,但结果相同)

invoke-command -computername mail1.dcloud.cisco.com -scriptblock {Get-host} 

PSComputerName   : mail1.dcloud.cisco.com
RunspaceId       : 6ccceb7b-5fa0-42b7-b78f-22b17116f4d3
Name             : ServerRemoteHost
Version          : 1.0.0.0
InstanceId       : 28263e00-11f9-4d78-98c2-f789659b23c8
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : 

===========
** Notice version is 2.0 when run locally on server.

2008 R2 v2

PS C:\> $env:ComputerName
MAIL1

PS C:\> get-host


Name             : ConsoleHost
Version          : 2.0
InstanceId       : d4cf14b5-5925-4fb5-9307-eaf8cbcd11f5
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace

12/2/17 美国东部时间 13:25 - 编辑: 如果我将命令更改为 enter-pssession,我会得到我认为正确的信息。

PS C:\python> enter-pssession mail1
Get-host


Name             : Windows PowerShell ISE Host
Version          : 4.0
InstanceId       : 7e3f6039-3b63-4c8e-af49-bc748c07ed7e
UI               :System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.Host.ISE.ISEOptions
IsRunspacePushed : True
Runspace         : System.Management.Automation.RemoteRunspace


[mail1]: PS C:\Users\Administrator.DCLOUD\Documents> exit-pssession

仍然没有弄清楚为什么Invoke-Command 会为命令Get-Host 提供不同的输出。

【问题讨论】:

    标签: powershell powershell-2.0 windows-server-2008-r2 windows-server-2012-r2


    【解决方案1】:

    Get-Host 返回当前主机的详细信息。如果您在 PowerShell 控制台中,它会返回控制台主机的版本。如果您在远程会话中,它会返回远程主机的版本(不是远程服务器中的 PS 版本)。

    注意:主机版本和 PowerShell 版本不同。

    即使 ISE 是 powershell 的不同主机

    【讨论】:

    • 感谢 Prasoon Karunan 的回答。我不知道。我会相应地调整我的脚本。
    猜你喜欢
    • 1970-01-01
    • 2010-10-01
    • 1970-01-01
    • 2013-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    相关资源
    最近更新 更多