PowerShell 输出在远程(调用命令)和本地命令之间不同

PowerShell output different between remote (invoke-command) and local commands

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

我的问题:

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

对于此示例,服务器 运行ning 远程调用命令是 运行ning Windows Server 2012 with PS 4 version。

正在测试的服务器是 运行ning Windows Server 2008 R2 with PS 2 版本。

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

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

2012 v4:

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

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 提供不同的输出。

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

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

甚至 ISE 也是 powershell 的不同主机