How to add a PSCmdlet or PSSnapin to hosted Powershell runtime without installing the snapin

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

  •  10-02-2021
  •  | 
  •  

문제

My scenario is as follows.

  • I am uploading my dll through web UI.
  • I am hosting a PowerShell runspace in an ASP.NET application.
  • I The DLL contains the PSCmdlet and would like to make use of it.
  • The PSCmdlet only needs to be accessible within the hosted runspace and does not need to be used in any external scenario.
  • The application does not have access to the windows registry as it runs with limited privileges, so I cannot install the PsSnapin.

Is it possible for me to use the commandlet without going through the installation process?

도움이 되었습니까?

해결책

If your use case is straightforward then it is possible. Please see these question: Hosted PowerShell cannot see Cmdlets in the same Assembly. Several answers there provide different ways, choose one that works better or you like more.

다른 팁

If you use PowerShell V2 you can use an unregistered snapin as a binary module.

Import-Module ‹path-to-dll›

add a -passthru to get the PSModuleInfo reference which describes the module.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top