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?
222 Views Asked by Mark At
1
There are 1 best solutions below
Related Questions in POWERSHELL
- PowerShell Linphone Configuration
- How avoid \t being converted to Tab in Powershell
- How do I get my terminal to work in VS Code? Exit Code:2, doesn't allow me to type anything
- Npm command not working in powershell but works in cmd
- Issue with path not being treated as encapsulated when calling cmd /C
- Native command throws error only when I redirect to a variable
- Logic Apps and long running Azure Function (Powershell)
- April fools - PsExec (PsTools)
- How to use nested ForEach-Object
- Batch Script-Powershell MessageBox | How do I set TopMost within PS command line of Batch?
- Execution Stuck at Get-PnPPage if function executed on Button Click
- How can I expand a column from group output?
- How to use expression in regex -replace with capturing group in powershell
- powershell where-object -cnotmatch filter unwanted lines
- How to make Visual Studio 2022 project launch Windows Terminal instead of PowerShell?
Related Questions in PSSNAPIN
- How to control Get-MailboxFolderStatistics output language?
- Running Powershell 5.1 in a C# / .NET Core 2.1 Application
- Path for Add-PSSnapin not correct when running PowerShell Script from C#
- How to Load Component Services/DCOM Config SnapIn
- Adding a snapin from a module not working like expected
- Powershell 5.1 snap in registration errors
- Oracle Snapins or modules availability
- SQL PowerShell Snapin Problems
- Powershell SnapIn when running in Visual Studio publish
- Snapins loaded from child, not in parent scope when separate files used for Classes
- Windows PowerShell snap-in 'Microsoft.Sharepoint.Powershell' is not installed on this computer?
- Exchange Management Tool Installation Error
- Register Powershell SnapIn to specific version of Powershell
- Powershell Backup snap-in in win7
- Use import-module with a PowerShell PSSnapin Dll
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.