8

Is it possible to import and invoke a Cmdlet from a DLL that is not in the PATH directories?

I want to write a build script with powershell that is able to compress the results. Therefore I found 7Zip4Powershell Cmdlets (Source), but I am unable to invoke them.

Karsten
  • 1,814
  • 2
  • 17
  • 32

1 Answers1

8

You can use the Import-Module command to load a PowerShell module. Therefore, you should be able to use:

Import-Module C:\Temp\7Zip4Powershell.dll
Alan
  • 2,962
  • 2
  • 15
  • 18
  • When I try this I get a BadImageFormatException. Could it be because I am using Powershell 2 and 7Zip4Powershell seems to be build with .NET Framework 4.0? – Karsten Jan 11 '15 at 12:45
  • 1
    Yes, it's almost certainly down to your PowerShell version. Type in `$psversiontable` and see what CLRVersion you're using - it'll be 2.0 in PowerShell 2. – Alan Jan 11 '15 at 12:47
  • 1
    When I tried it with PS 3 it worked, but I had to unblock the dll first, because it was downloaded from the internet. – Karsten Jan 11 '15 at 15:27