Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

How to automate either PowerShell or PowerShell Core for same machine

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 - for building PowerShell Core (v6+) applications, based on .NET Core / 5+ (cross-platform).

    • 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 - for building modules and hosts that are compatible with both Windows PowerShell and PowerShell Core (cross-platform) - but note:

    • "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 - not recommended for direct use.


As for targeting a specific edition / version via remoting:

  • See this question and answer

  • 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.


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

  • powershell.exe - Windows PowerShell

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...