如何为同一台机器自动化 PowerShell 或 PowerShell Core [英] How to automate either PowerShell or PowerShell Core for same machine

查看:11
本文介绍了如何为同一台机器自动化 PowerShell 或 PowerShell Core的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

With the release of PowerShell Core, how can an application choose which version of Powershell (Powershell 5.x or PowerShell Core) is being called when it using hosting automation library (system.management.automation)? Something about the runspace that should be created? or maybe the connection info?

推荐答案

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

Here's an overview of the PowerShell SDK-related NuGet packages:Adapted from here.

  • Microsoft.PowerShell.5.ReferenceAssemblies - for building Windows PowerShell applications, based on the .NET Framework (Windows-only).

Microsoft.PowerShell.SDK - 用于构建 PowerShell Core (v6+) 应用程序,基于 .NET Core/5+(跨平台).

Microsoft.PowerShell.SDK - for building PowerShell Core (v6+) applications, based on .NET Core / 5+ (cross-platform).

  • 要确定给定的包版本必须至少与哪个特定的 .NET (Core) 运行时结合,请在链接页面上选择感兴趣的包版本,展开 Dependencies 部分,然后查阅第一个条目;例如,对于包版本 7.2.0,所需的最低 .NET (Core) 运行时为 net6.0.
  • To determine what specific .NET (Core) runtime a given package version must be combined with at a minimum, select the package version of interest on the linked page, expand the Dependencies section, and consult the first entry; e.g., for package version 7.2.0 the minimum required .NET (Core) runtime is net6.0.

PowerShellStandard.Library -用于构建与Windows PowerShell 和 PowerShell Core(跨平台)兼容的模块和主机 - 但注意:

PowerShellStandard.Library - for building modules and hosts that are compatible with both Windows PowerShell and PowerShell Core (cross-platform) - but note:

  • "PowerShell Standard 是一个参考程序集,旨在帮助开发人员创建将在 PowerShell 上运行的模块和 PowerShell 主机.参考程序集不包含实际实现,而是允许您仅使用存在于不同 PowerShell 版本中的 API.这意味着您仍然需要在 PowerShell 运行时中运行."

  • "PowerShell Standard is a reference assembly that has been created to assist developers in creating modules and PowerShell hosts which will run on PowerShell. The reference assembly contains no actual implementation but rather will allow you to use only APIs that exist across different versions of PowerShell. This means that you still need to run within a PowerShell runtime."

要创建独立应用程序,请使用前两个包之一.

For creating stand-alone applications, use one of the first two packages.

System.Management.Automation - 不建议直接使用.

System.Management.Automation - not recommended for direct use.

至于通过远程处理针对特定版本/版本:

As for targeting a specific edition / version via remoting:

请注意,它涵盖了使用 PowerShell cmdlets 的角度的远程处理,而不是 SDK,不过您也可以随时通过 SDK 调用 cmdlet.

Note that it covers remoting from the perspective of using PowerShell cmdlets, not the SDK, though you can always call the cmdlets via the SDK as well.

正如 Lee Daily 在评论中指出的那样,特定于版本的可执行文件名 是:

As Lee Daily points out in a comment, the edition-specific executable filenames are:

  • powershell.exe - Windows PowerShell

pwsh.exe (Windows)/pwsh(类 Unix 平台) - PowerShell Core

pwsh.exe (Windows) / pwsh (Unix-like platforms) - PowerShell Core

这篇关于如何为同一台机器自动化 PowerShell 或 PowerShell Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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