Thanks Adrian and Peter! Here's a modified version of Peter's Get-Bitness that 1) takes a list of files to examine from the pipeline, and 2) doesn't die it if looks at a non-.NET DLL (e.g. if it looks at certain C++ DLLs):
# example usage: dir *.exe,*.dll | Get-PEKind
function Get-PEKind {
Param(
[Parameter(Mandatory=$True,ValueFromPipeline=$True)]
[System.IO.FileInfo]$assemblies
)
Process {
foreach ($assembly in $assemblies) {
$peKinds = new-object Reflection.PortableExecutableKinds
$imageFileMachine = new-object Reflection.ImageFileMachine
try
{
$a = [Reflection.Assembly]::LoadFile($assembly.Fullname)
$a.ManifestModule.GetPEKind([ref]$peKinds, [ref]$imageFileMachine)
}
catch [System.BadImageFormatException]
{
$peKinds = [System.Reflection.PortableExecutableKinds]"NotAPortableExecutableImage"
}
$o = New-Object System.Object
$o | Add-Member -type NoteProperty -name File -value $assembly
$o | Add-Member -type NoteProperty -name PEKind -value $peKinds
Write-Output $o
}
}
}
I'm new to PowerShell, so this may not be an example of best practices.
Alternatively, according to https://stackoverflow.com/a/4719567/64257 there may also be a handy Get-PEHeader cmdlet in the PowerShell Community Extensions.