I have a PowerShell snapin, and I would like 开发者_StackOverflowto 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?
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.
精彩评论