I have created a simple PowerShell module in c# which implements a few cmdlets and I would like to be able to run code when the module is imported.
From looking around on google and in the namespace there doesn't appear to be a proper way of doing this.
The work around I have come up with so far is to either create a psm1 or ps1 file that runs when the module is loaded and does the startup actions (would rather not use this as scripts are blocked on some environments this will run on).
Other option is I have been able to do it by creating a CmdletProvider which works but it creates a junk entry in the list of providers when using new-psdrive.
[CmdletProvider("junkprovider", ProviderCapabilities.None)]
public class Startup : CmdletProvider
{
Public Startup()
{
// Startup code here
}
}
Is there a way to do this properly or am I going to have to use hacks?