【问题标题】:Setting Powershell version used in the PowerShell host?设置 PowerShell 主机中使用的 Powershell 版本?
【发布时间】:2020-11-06 12:31:51
【问题描述】:

我正在使用 .NET PowerShell 主机。我安装了 PowerShell 版本 5 和 7。运行时:

$PSVersionTable.PSVersion

  • 返回:

主要次要版本修订


5 1 18362 1110

如何让它运行 PowerShell 版本 7?

【问题讨论】:

  • “我正在使用 .NET PowerShell 主机”,我认为这意味着针对 .NET Framework 进行编译? PowerShell 7 在 .NET Core >3.1 上运行,因此您将无法从 .NET Framework 主机使用它。
  • 是的,正确的。说得通。谢谢。

标签: c# .net powershell


【解决方案1】:

根据 Microsoft 的文档,您应该能够加载以前版本的 PowerShell。

单独的安装路径和可执行文件名

PowerShell 7 安装到一个新目录,支持与 Windows PowerShell 5.1 并行执行。

按版本安装位置:
Windows PowerShell 5.1:$env:WINDIR\System32\WindowsPowerShell\v1.0
PowerShell 核心 6.x:$env:ProgramFiles\PowerShell\6
PowerShell 7:$env:ProgramFiles\PowerShell\7

新位置已添加到您的 PATH,允许您同时运行 Windows PowerShell 5.1 和 PowerShell 7。如果您要从 PowerShell Core 6.x 迁移到 PowerShell 7,则会删除 PowerShell 6 并替换 PATH .

在 Windows PowerShell 中,PowerShell 可执行文件名为 powershell.exe。在版本 6 及更高版本中,可执行文件名为 pwsh.exe。新名称使支持两个版本的并行执行变得容易。

使用提供的链接阅读网页。

https://docs.microsoft.com/en-us/powershell/scripting/install/migrating-from-windows-powershell-51-to-powershell-7?view=powershell-7

【讨论】:

    【解决方案2】:

    Powershell (Core) 7 是 different executable: pwsh.exe

    powershell => Windows PowerShell (latest: v5.1)
    pwsh => PowerShell Core (latest: v7)
    

    【讨论】:

      【解决方案3】:

      从控制台就可以了

      where powershell.exe
      
      -and-
      
      where pwsh.exe
      

      你应该得到:

      C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
      
      -and-
      
      C:\APL\Microsoft\PowerShell64\pwsh.exe
      

      然后你可以直接调用 .exe(s)...
      绕过 .cmd(s)/.bat(s)/.lnk(s)/alias/hijackers/etc 的任何问题。等等

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-09-21
        • 1970-01-01
        • 2022-10-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多