Forked from mattifestation/autodump_powershell_process.ps1
Created
October 17, 2016 04:15
-
-
Save opexxx/cd10ce579d29c2fbc1871c07be7b9c2e to your computer and use it in GitHub Desktop.
Automatically capture a full PowerShell memory dump upon any PowerShell host process termination
This file contains hidden or 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
| $EventFilterArgs = @{ | |
| EventNamespace = 'root/cimv2' | |
| Name = 'PowerShellProcessStarted' | |
| Query = 'SELECT FileName, ProcessID FROM Win32_ModuleLoadTrace WHERE FileName LIKE "%System.Management.Automation%.dll"' | |
| QueryLanguage = 'WQL' | |
| } | |
| $Filter = New-CimInstance -Namespace root/subscription -ClassName __EventFilter -Property $EventFilterArgs | |
| $CommandLineConsumerArgs = @{ | |
| Name = 'PowershellMemoryCapture' | |
| CommandLineTemplate = 'procdump.exe -accepteula -g -e -t -ma %ProcessID% C:\dumps' | |
| } | |
| $Consumer = New-CimInstance -Namespace root/subscription -ClassName CommandLineEventConsumer -Property $CommandLineConsumerArgs | |
| $FilterToConsumerArgs = @{ | |
| Filter = [Ref] $Filter | |
| Consumer = [Ref] $Consumer | |
| } | |
| $FilterToConsumerBinding = New-CimInstance -Namespace root/subscription -ClassName __FilterToConsumerBinding -Property $FilterToConsumerArgs | |
| <# Cleanup | |
| Get-CimInstance -Namespace root/subscription -ClassName __EventFilter | Remove-CimInstance | |
| Get-CimInstance -Namespace root/subscription -ClassName __EventConsumer | Remove-CimInstance | |
| Get-CimInstance -Namespace root/subscription -ClassName __FilterToConsumerBinding | Remove-CimInstance | |
| #> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment