I have a C# module and I would like to define some constants for use with the parameters and switches, rather than using numeric values, e.g. my-cmdlet -command write_data rather than my-cmdlet -command 4. From what I know, I can use SessionState.PSVariable.Set to create these constants. So, I need a method of getting called for one-time initialization when my module is imported. How do I do that? Also, is there a method to get called when the module is unloaded?
Asked
Active
Viewed 71 times
0
-
Not sure if you are trying to say that how would you run a c# code in PS or not? If yes, you can do `Add-Type -ReferencedAssemblies $Assem -TypeDefinition $Source -Language CSharpVersion3` in powershell which will execute the c# code in Powershell. In $Source, you can put all your c# code. – Ranadip Dutta Aug 17 '17 at 03:42
-
https://stackoverflow.com/a/38316467 – user4003407 Aug 17 '17 at 12:18
-
No, I have a PowerShell module written in C#, and I want to be called when the module is loaded – Brian Aug 17 '17 at 17:13
-
Related: [Export Powershell 5 enum declaration from a Module](https://stackoverflow.com/q/40348069/3439404) – JosefZ Sep 26 '19 at 11:31