gpt4 book ai didi

powershell - 如何为同一台机器自动化 PowerShell 或 PowerShell Core

转载 作者:行者123 更新时间:2023-12-04 12:10:46 28 4
gpt4 key购买 nike

随着 PowerShell Core 的发布,应用程序在使用托管自动化库 (system.management.automation) 时如何选择调用哪个版本的 Powershell(Powershell 5.x 或 PowerShell Core)?关于应该创建的运行空间的一些事情?或者也许是连接信息?

最佳答案

以下是 PowerShell SDK 相关 NuGet 包的概述 :改编自 here

  • Microsoft.PowerShell.5.ReferenceAssemblies - 用于构建 Windows PowerShell 应用程序,基于 .NET Framework (仅限 Windows)。
  • Microsoft.PowerShell.SDK - 用于构建 PowerShell Core (v6+) 应用程序,基于 .NET Core/5+ (跨平台)。
  • 要确定给定包版本必须至少与哪个特定的 .NET (Core) 运行时结合,请在链接页面上选择感兴趣的包版本,展开 Dependencies 部分,并查阅第一个条目;例如,对于包版本 7.2.0 所需的最低 .NET (Core) 运行时是 net6.0

  • PowerShellStandard.Library - 用于构建与 Windows PowerShell 和 PowerShell Core (跨平台)兼容的 模块和主机 - 但 note :
  • "PowerShell Standard 是一个 引用程序集 ,它的创建是为了帮助开发人员在 创建模块和 PowerShell 主机,这些模块和 PowerShell 主机将在 PowerShell 上运行 只允许使用 107 你104567920 的实际引用程序集 的实现 API 只包含 504567920 的 API。存在于不同版本的 PowerShell。这意味着 您仍然需要在 PowerShell 运行时中运行。
  • 要创建独立应用程序,请使用前两个包之一。

  • System.Management.Automation - 不推荐直接使用。

  • 至于通过远程处理针对特定版本/版本:
  • this question and answer
  • 请注意,它从使用 PowerShell cmdlet 的角度而不是 SDK 的角度介绍了远程处理,尽管您始终也可以通过 SDK 调用 cmdlet。

  • 正如 Lee Daily 在评论中指出的那样,特定于版本的 可执行文件名 是:
  • powershell.exe - Windows PowerShell
  • pwsh.exe (Windows)/pwsh (类 Unix 平台) - PowerShell Core
  • 关于powershell - 如何为同一台机器自动化 PowerShell 或 PowerShell Core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58211358/

    28 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com