Created
August 10, 2018 15:42
-
-
Save vexx32/57bdfb0e37c176940e94edde12f839e2 to your computer and use it in GitHub Desktop.
Creates a test module that unconditionally throws an exception during the remove-module call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$Module = New-Module -Name 'ImportMe' -ScriptBlock { | |
class TryMeException : System.Exception { | |
TryMeException() : base() {} | |
TryMeException([string]$Message) : base($Message) {} | |
} | |
$onremove = { | |
throw [TryMeException]::new("HOW DARE YOU STEAL THAT CAR") | |
} | |
$ExecutionContext.SessionState.Module.OnRemove += $onremove | |
} | |
Import-Module $Module | |
Remove-Module -Name 'ImportMe' | |
Get-Module 'ImportMe' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment