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

查看:188
本文介绍了如何为同一台机器自动化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 -用于构建基于 .NET Core (跨平台)的PowerShell Core 应用程序.

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

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:

请注意,尽管您也可以始终通过SDK调用cmdlet,但它涵盖了从使用PowerShell cmdlet 而不是SDK的角度.

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天全站免登陆