How to automate either PowerShell or PowerShell Core for same machine

岁酱吖の 提交于 2020-05-28 05:30:27

问题


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?


回答1:


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 applications, based on .NET Core (cross-platform).

  • 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



来源:https://stackoverflow.com/questions/58211358/how-to-automate-either-powershell-or-powershell-core-for-same-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!