简体   繁体   English

以版本2运行远程Powershell会话

[英]Run remote Powershell session as version 2

I'm on a server that is running Powershell Version 2: 我在运行Powershell版本2的服务器上:

PS C:\> $PSVersionTable

Name      Value
----      -----
...
PSVersion 2.0

I then create a new remote session to a different computer and connect to it: 然后,我创建到另一台计算机的新远程会话并连接到它:

$sess = New-PSSession -ComputerName {ComputerName} -Credential $credential

It returns me the result: 它给我返回结果:

PS C:\> Invoke-Command -Session $sess -ScriptBlock { $PSVersionTable }

Name      Value
----      -----
...
PSVersion 3.0

However, I need Powershell to be in Version 2 for my script so I enter a session (to make it easier). 但是,我需要Powershell处于脚本的第2版中,因此我进入一个会话(以使其更容易)。 I then try to get Powershell to be Version 2: 然后,我尝试使Powershell成为版本2:

C:\> Enter-PSSession -Session $sess
[{ComputerName}]: PS C:\> Powershell -Version 2
Windows Powershell
Copyright (C) 2009 Microsoft Corporation. All rights reserverd

And then it just hangs (or at least never lets me enter anything else into the console until I Ctrl-C). 然后它挂起(或者至少在我按Ctrl-C之前,至少不要让我在控制台中输入其他任何内容)。

I've also tried going through the Invoke-Command: 我也尝试过执行Invoke-Command:

PS C:\> Invoke-Command -Session $sess -ScriptBlock { Powershell -version 2 }

and it does the same. 它也一样。

I've also tried to register a PSSessionConfiguration as per here: https://technet.microsoft.com/en-us/library/hh847899.aspx 我也尝试按照这里注册PSSessionConfiguration: https : //technet.microsoft.com/zh-cn/library/hh847899.aspx

PS C:\> Register-PSSessionConfiguration -Name PS2 -PSVersion 2.0

But I get: 但是我得到:

Register-PSSessionConfiguration: a parameter cannot be found that matches parameter name 'PSVersion'.

Does anyone have any ideas of what I can try next?! 有人对我接下来可以尝试的东西有任何想法吗? Thanks 谢谢

On what machine did you run Register-PSSessionConfiguration ?. 您在哪台计算机上运行Register-PSSessionConfiguration Your computer or the "server"? 您的计算机还是“服务器”?

You need to make the configuration on the target server . 您需要在目标服务器上进行配置。 That is what you will be running the hosted PSSessionConfiguration. 那就是您将要运行的PSSessionConfiguration。

I just tried the steps in the technet article and it worked perfectly. 我只是尝试了Technet文章中的步骤,所以效果很好。 My 2008 server remoted to my windows 7 machine running a 2.0 PSSessionConfiguration. 我的2008服务器远程到运行2.0 PSSessionConfiguration的Windows 7计算机。

On target server/host: 在目标服务器/主机上:

Register-PSSessionConfiguration -Name PS2 -PSVersion 2.0

Then, on the client machine, reference the 'PS2' configuration. 然后,在客户端计算机上,参考“ PS2”配置。

$s = New-PSSession -ComputerName Server01 -ConfigurationName PS2

I take it that the following doesn't work either: 我认为以下方法也不起作用:

 #Requires -version 2.0

Another kluge you could try is to create a scheduled task on the target and have the task fire off your script with Powershell.exe -version 2 您可以尝试的另一种方法是在目标上创建计划任务,并使用Powershell.exe -version 2使任务启动脚本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM