Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

powershell: run code when importing module

Tags:

powershell

I have developed a powershell module in C#, implemented a few commands.

How can I execute C# code in this module when it's imported by Powershell?

like image 438
Mr Dudemeister Avatar asked Jul 02 '26 03:07

Mr Dudemeister


1 Answers

Create a module manifest with the ModuleToProcess (or RootModule in V3) field set to the PSM1 file and the NestedModules set to the DLL e.g.:

RootModule         = 'Pscx.psm1'
NestedModules      = 'Pscx.dll' 

This is what we do in the PowerShell Community Extensions where we do the same thing - fire up a script first. You can see our PSD1 file here.

like image 141
Keith Hill Avatar answered Jul 05 '26 01:07

Keith Hill



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!