【发布时间】: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