How to log a output status of each dll's files registered using regsvr32 command in power shell script

StackOverflow https://stackoverflow.com/questions/22588995

  •  19-06-2023
  •  | 
  •  

Question

I want to register few dll's using regsvr32 command in powershell.

I have created a foreach command to do it. In this case, some dll's might fail to register and I want to log each dll status in a log file.

This is what I have created so far

$dllfiles = @("1.dll","2.dll","3.dll","4.dll")

$dllfiles | ForEach {regsvr32 /s $_}
Was it helpful?

Solution

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top