How to register a powershell snapin programmatically in a hosted powershell environment?

StackOverflow https://stackoverflow.com/questions/7491570

  •  24-01-2021
  •  | 
  •  

Вопрос

I've developed some powershell cmdlets and providers, and also developed an application to host powershell environment. I would like to run those cmdlets and providers in this hosted powershell environment. I'm wondering whether this is possible and how to register my custom snapin. Thanks for the help.

Это было полезно?

Решение

The default installer for a PSSnapin extended class creates a series of registry keys for the snapin. These are created under HKLM:\SOFTWARE\Microsoft\PowerShell\1\PowerShellSnapIns\. The string values are: PowerShellVersion, Vendor, Description, Version, ApplicationBase, AssemblyName, ModuleName, VendorIndirect and DescriptionIndirect.

Look at an existing registered PSSnapin and use that as for your template to create the key and the string values. After creating the key and all the string values (especially the ApplicationBase, AssemblyName and ModuleName values) then add the snapin to a PSRunspaceConfiguration object with the AddPSSnapin() method before you instantiate a new runspace object.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top