You need to run the command in cmd
for it to set $?
and $LASTEXITCODE
correctly:
$dllfiles | % {
& cmd /c regsvr32 /s $_
if ($?) {
"$_ registered correctly."
} else {
"Registration of $_ failed. ($LASTEXITCODE)"
}
}
[http://huddledmasses.org/register-dll-calling-regsvr32-without-messageboxes-in-powershell/] (page was apparently removed by the author)