同时使用台式机Powershell 5.1和Powershell Core 6.1 [英] Using both desktop Powershell 5.1 and Powershell Core 6.1

查看:75
本文介绍了同时使用台式机Powershell 5.1和Powershell Core 6.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在VS Code中使用PS.Core 6.1-将其设置为默认外壳,使用它打开PS调试会话,打开其控制台,等等...

I was playing with PS.Core 6.1 in my VS Code - made it the default shell, opened PS debugging sessions with it, opened its console, etc ...

现在,我将打开常规的台式机Powershell 5.1并获取此信息:

Now I am opening the regular desktop Powershell 5.1 and get this:

Windows PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\Users\me> get-module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PS...


PS C:\Users\me> $env:PSModulePath -split ';'
C:\Users\me\Documents\PowerShell\Modules
C:\Program Files\PowerShell\Modules
c:\program files\powershell\6\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
PS C:\Users\me>

这不好. PS.Core 6.1安装了自己的Microsoft.PowerShell.Utility模块,该模块与台式机版本不兼容.

This is not good. The PS.Core 6.1 installed its own Microsoft.PowerShell.Utility module which is incompatible with the desktop version.

PSModulePath环境变量现在将PS.Core 6模块与台式机模块一起列出,甚至具有更高的优先级.即使我没有在控制面板"中看到它,也是如此:

The PSModulePath environment variable now lists the PS.Core 6 modules alongside the desktop modules, even with higher priority. Even though I do not see it in the Control Panel:

真是一团糟.

编辑1

当我从任务栏中的快捷方式启动外壳程序时,会发现混乱.台式机的目标是 C:\ Windows \ System32 \ WindowsPowerShell \ v1.0 \ powershell.exe ,而核心的目标是"C:\ Program Files \ PowerShell \ 6 \ pwsh.exe" -WorkingDirectory〜

The mess I observe is when I launch the shells from the shortcuts I have in the taskbar. The desktop one targets C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe and the core one - "C:\Program Files\PowerShell\6\pwsh.exe" -WorkingDirectory ~

编辑2

因此,无论如何,PS.Core的安装或我对VS.Code的实验都更新了父explorer.exe进程的环境.我在这里进行描述- PSModulePath环境属性如何组成?

So, somehow, either installation of PS.Core or my experimentation with VS.Code has updated the environment of the parent explorer.exe process. I describe it here - How does PSModulePath environment property get composed?

可能是PS.Core安装中的一个错误,这意味着这是一次性的事情.还是VS Code中的错误,这意味着我可以再次将其搞砸.

Could be a bug in the installation of PS.Core, which means it is a one time thing. Or a bug in VS Code, which means I could screw it again.

推荐答案

我认为问题可能在于将PowerShell Core 6.1设置为默认外壳.

I think the issue might be setting PowerShell Core 6.1 as your default shell.

如果我从cmd提示符启动PowerShell 5.1(powershell.exe):

If I launch PowerShell 5.1 (powershell.exe) from cmd prompt:

Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.

C:\>powershell.exe
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.2879
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.2879
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\> Get-Module -ListAvailable Microsoft.PowerShell.Utility


    Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Format-List, Format-Custom, Format-Table, Format-Wide...}

我得到了预期的模块版本.

I get the expected module version.

如果我从cmd提示符启动PowerShell Core 6.1(pwsh.exe):

If I launch PowerShell Core 6.1 (pwsh.exe) from cmd prompt:

C:\>pwsh.exe
PowerShell 6.1.3
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.3
PSEdition                      Core
GitCommitId                    6.1.3
OS                             Microsoft Windows 10.0.14393
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


PS C:\> Get-Module -ListAvailable Microsoft.PowerShell.Utility


    Directory: C:\program files\powershell\6\Modules


ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        Core      {Format-List, Format-Custom, Format-Table, Forma...

我得到了预期的模块版本.

I get the expected module version.

现在,如果我先从cmd提示符启动PowerShell Core 6.1,则然后从PowerShell Core 6.1启动PowerShell 5.1(即就像您将默认Shell设置为PowerShell Core 6.1一样):

Now, if I launch PowerShell Core 6.1 from cmd prompt first, then launch PowerShell 5.1 from PowerShell Core 6.1 (i.e. as if you set your default shell to PowerShell Core 6.1):

C:\>pwsh.exe
PowerShell 6.1.3
Copyright (c) Microsoft Corporation. All rights reserved.

https://aka.ms/pscore6-docs
Type 'help' to get help.

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.3
PSEdition                      Core
GitCommitId                    6.1.3
OS                             Microsoft Windows 10.0.14393
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0


PS C:\> Get-Module -ListAvailable Microsoft.PowerShell.Utility


    Directory: C:\program files\powershell\6\Modules


ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        Core      {Format-List, Format-Custom, Format-Table, Forma...


PS C:\> powershell.exe
Windows PowerShell
Copyright (C) 2016 Microsoft Corporation. All rights reserved.

PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.14393.2879
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.14393.2879
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1


PS C:\> Get-Module -ListAvailable Microsoft.PowerShell.Utility


    Directory: C:\program files\powershell\6\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        {Format-List, Format-Custom, Format-Table, Format-Wide...}


    Directory: C:\Windows\system32\WindowsPowerShell\v1.0\Modules


ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Format-List, Format-Custom, Format-Table, Format-Wide...}

我列出了两个模块.而当我导入模块时:

I get both modules listed. And when I import the module:

PS C:\> Import-Module Microsoft.PowerShell.Utility
PS C:\> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   6.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemPropert...
Manifest   6.1.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl...
Manifest   6.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest   6.1.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, En...
Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PS...

已加载较新版本(6.1)!

The newer version (6.1) is loaded!

我同意这是意外情况.

好消息是,我们也可以通过指定-MaximumVersion来访问旧模块:

The good news is that we can access the old module as well, by specifying the -MaximumVersion:

PS C:\> Import-Module Microsoft.PowerShell.Utility -MaximumVersion 3.1.0.0
PS C:\> Get-Module

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Manifest   6.1.0.0    Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty...}
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Script     2.0.0      PSReadline                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler...}

这篇关于同时使用台式机Powershell 5.1和Powershell Core 6.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆