0

We have a legacy PowerShell PsSnapin (c#). I want to avoid having to use InstallUtil. The following imports a module with the PSSnapin cmdlets exported:

import-module .\MySnapin.dll

However, when I run the module cmdlets, they fail due to not being able to find referenced assemblies (specifically, Enterprise Library dlls).

Is there a neat way to get this working?

(The PsSnapin dll and all referenced assemblies are in the same build directory, and when I use installutil, the dependencies are all resolved correctly)

Rob
  • 4,327
  • 6
  • 29
  • 55

1 Answers1

0

Snap-ins are a bit different from Modules. You first need to register the snap-in, using InstallUtil.exe:

PS> $InstallUtil = Join-Path $([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory()) "InstallUtil.exe"
PS> & $InstallUtil "C:\Path\to\MySnapin.dll"

After registering the snapin assembly, you can load it into your powershell session with Add-PSSnapin:

PS> Add-PSSnapIn MySnapin
Mathias R. Jessen
  • 157,619
  • 12
  • 148
  • 206
  • indeed - that's what we usually do, but I was explicitly trying to avoid InstallUtil. E.g. so I can load two versions of the same snapin, etc. – Rob Jan 07 '16 at 17:03
  • Ahh, I see. I don't know if this is viable but: Rename one version, recompile, register both, shift between them with `Add/Remove-PSSnapIn` perhaps? – Mathias R. Jessen Jan 07 '16 at 17:25