0

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.

user310291
  • 36,946
  • 82
  • 271
  • 487

1 Answers1

1

tl;dr

  • You fundamentally cannot use PowerShell (Core) in-process (by loading an assembly (.dll)) from a Windows PowerShell session.

    • Any cross-edition calls, if needed, require out-of-process operation.
  • 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:

  • There is no 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:

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 }
    
    • Note the use of a script block ({ ... }) 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.

mklement0
  • 382,024
  • 64
  • 607
  • 775