How can I run initialization code each time my snap-in is loaded?

147 views Asked by At

I have a PowerShell snapin, and I would like to run a bit of initialization code (hooking some AppDomain events) each time my snapin is loaded (i.e. once for each powershell.exe process that is started). How can this be accomplished?

1

There are 1 answers

0
Keith Hill On BEST ANSWER

One approach, and this is probably a bit rube-goldberg in nature, is to hook into a provider's startup code. This assumes that in your snapin configuration you have declared a default drive to initialize. It just so happens that in PSCX we use a provider to store all of our settings and global variables to minimize impact on the user's global session space. The initialization of this settings drive provided a convenient place for us to hook in other initialization code.

Now if we weren't creating a provider, I assume there is some other way to initialize code early but I don't know off the top of my head.