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?
-
1windows powershell = `powershell.exe` ///// powershell 6+ = `pwsh.exe` [*grin*] – Lee_Dailey Oct 03 '19 at 02:06
1 Answers
Here's an overview of the PowerShell SDK-related NuGet packages:Adapted from here.
Note: is not recommended for direct use.System.Management.Automation
To create stand-alone applications that host the PowerShell runtime in order to call PowerShell commands in-process:
Use
Microsoft.PowerShell.5.ReferenceAssemblies
for .NET Framework (Windows-only) applications using the legacy Windows PowerShell runtime.Use
Microsoft.PowerShell.SDK
for (potentially cross-platform) .NET Core / 5+. applications using the PowerShell (Core) v6+ runtime.- 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 version7.2.0
the minimum required .NET (Core) runtime isnet6.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
To create assemblies that implement cmdlets / form part of modules for use in PowerShell or to create a PowerShell host:
Use
PowerShellStandard.Library
; it is compatible with both Windows PowerShell and PowerShell (Core) v6+, but note:- "[This] 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."
As for targeting a specific edition / version via remoting:
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 Dailey points out in a comment on the question, the edition-specific executable filenames are:
powershell.exe
- Windows PowerShellpwsh.exe
(Windows) /pwsh
(Unix-like platforms) - PowerShell (Core) v6+

- 382,024
- 64
- 607
- 775