I have installed Powershell Core on Windows.
I want to do
Add-Type -Path PSCore.dll
but I get path error message. How can I find the path ?
Update: I installed Powershell core but still says Add-Type: Cannot bind parameter 'Path' to the target.
I have installed Powershell Core on Windows.
I want to do
Add-Type -Path PSCore.dll
but I get path error message. How can I find the path ?
Update: I installed Powershell core but still says Add-Type: Cannot bind parameter 'Path' to the target.
tl;dr
You fundamentally cannot use PowerShell (Core) in-process (by loading an assembly (.dll)) from a Windows PowerShell session.
Typically, you use one or the other edition of PowerShell, e.g. by starting an interactive session via the respective CLI (powershell.exe for Windows PowerShell, pwsh.exe for PowerShell (Core)).
As an aside:
PSCore.dll, and Add-Type -Path PSCore.dll would look in the current directory only, whereas you need to use -AssemblyName instead of -Path to look for assemblies in the GAC (Windows PowerShell) / among the assemblies that PowerShell ships with (PowerShell (Core)), using the assembly name (typically the same as the .dll base filename, but the .dll part mustn't be specified).There are two independent PowerShell editions, which have distinct CLIs and SDKs:
Windows PowerShell, up to v5.1.x, the legacy, ships-with-Windows edition, is built on top of the legacy .NET Framework.
CLI: powershell.exe
SDK (usable from any .NET application): Microsoft.PowerShell.5.ReferenceAssemblies
PowerShell (Core), v6 and above, the install-on-demand, cross-platform edition, which is built on the cross-platform .NET (Core) / .NET 5+ runtime.
pwsh.exe (just pwsh on Unix-like platforms)Microsoft.PowerShell.SDKNote: There's also a SDK package for creating cmdlets and hosts that can run in either edition - see this answer for details.
Cross-edition calls:
In either direction, you can use the respective other edition's CLI to make a call to it, which invariably runs in a child process; e.g.:
# Call PS Core from Windows PowerShell
pwsh -NoProfile { $PSVersionTable }
{ ... }) for passing the command, which avoids quoting headaches and - within limits - preserves the types of the input and output objects, as you would get when using PowerShell's remoting features - see this answer for details.From PowerShell (Core), specifically:
While the current version of PowerShell (Core) is almost at feature parity with Windows PowerShell, there is functionality that either hasn't been ported yet, or cannot be ported due to lack of support in the underlying .NET (Core) APIs.
To ease the pain of migrating to PowerShell (Core), the Windows compatibility feature allows near-seamless use of Windows PowerShell-only modules from PowerShell (Core), but note that, behind the scenes, a Windows PowerShell child process is of necessity involved, and the aformentioned limits to type fidelity apply equally.