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?
How can I run initialization code each time my snap-in is loaded?
218 Views Asked by Mark At
1
There are 1 best solutions below
Related Questions in POWERSHELL
- How to ignore warning errors?
- Data execution plan ended with error on DB restore
- Powershell Split a file name
- PowerShell EWS Save as for e-mails
- Run SQL Server Update Statement With Powershell
- using a global variable in multiple functions powershell
- Heisenberg was here: Aliases for PowerShell parameters only appear in cmdlet help when you do NOT document the cmdlet
- PowerShell Script to add newuser
- Why is PowerShell "not recognized" when installing Chocolatey?
- Enumerate a PSCustomObject as key/value pairs
- Unable to start program outside Windows folder
- Ask for creds only if some specified
- PowerShell 3 Parameters
- i can't ping a computer but remoting into it works (powershell enter-pssession)
- Feeding Variables in new-aduser -path option in powershell
Related Questions in PSSNAPIN
- PowerShell Snapin Cmdlet CommandNotFoundException
- Register Powershell SnapIn to specific version of Powershell
- How to control Get-MailboxFolderStatistics output language?
- Windows PowerShell snap-in 'Microsoft.Sharepoint.Powershell' is not installed on this computer?
- Powershell Backup snap-in in win7
- Oracle Snapins or modules availability
- Powershell 5.1 snap in registration errors
- Cmdlet Contention between PowerShell SnapIns
- How can I run initialization code each time my snap-in is loaded?
- Is Make-Shell deprecated?
- Use BAT file to check if PSSnapin is registered
- Add Powershell Snapin for Powershell Module and Import Multiple Times
- PowerShell Modules and SnapIns
- uninstallation of a powershell cmdlet
- How to Load Component Services/DCOM Config SnapIn
Related Questions in POWERSHELL-SDK
- Powershell editor with intellisense that I can embed into my program?
- Data From PSObject C#
- C# PowerShell does not capture PowerShell.Streams when using AddCommand but does when using AddScript
- Cannot Execute Command "New-ItemProperty" Properly
- Invoked PS command to string
- PowerShell running local from published Single Exe fails (without IncludeAllContentForSelfExtract)
- Capturing all streams in correct sequence with PowerShell SDK
- How can I run initialization code each time my snap-in is loaded?
- Custom PowerShell Host and Converting PSObject back to base type
- Setting a proxy within a powershell script that is started by a C# application
- How to execute a powershell script using c# and setting execution policy?
- Powershell command not recognized when calling from C#
- PowerShell Object returns null
- The state of the current PowerShell instance is not valid for this operation in C#
- Whats the correct way to get output for this Powershell in C#
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
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.