title: PowerShell - Check digital signature and versions of dlls/exe in MSI
body: <p>I have a script that can verify if dlls/exe files holds the right versions and if they signed.
  The script is working for ZIP that contains files inside, ZIP that contains VIP that contains dlls and VIP that contains dlls, I need to add a test for MSI that contains dlls and exe files. at the end there is a if for cab that I would like to know how to do the checking for cabs. But the real issue is to add with more if the MSI verification. The MSI could be in folder inside a ZIP or in CAB file. ZIP file can be include more than one MSI</p>
  <pre><code>Add-Type -AssemblyName System.IO.Compression, System.IO.Compression.FileSystem
  
  write-host
  $path = Read-Host -Prompt &quot;Please enter a path where the ZIP/VIP are located&quot; 
  write-host
  $tempFolder = Join-Path ([IO.Path]::GetTempPath()) (New-GUID).ToString('n')
  $compressedfiles = Get-ChildItem -path $path\* -Include &quot;*.vip&quot;,&quot;*.zip&quot;#,&quot;*cab&quot;
  
  foreach ($file in $compressedfiles) 
  {   
      if ($file -like &quot;*.zip&quot;)
      {
       try 
       { 
          $zip = [System.IO.Compression.ZipFile]::ExtractToDirectory($file, $tempFolder)
          $test = Get-ChildItem -path $tempFolder\* -Include &quot;*.vip&quot; 
         
          if ($test)
          {
              $zip2 = [System.IO.Compression.ZipFile]::ExtractToDirectory($test, $tempFolder)
              $dlls = Get-ChildItem $tempFolder -Include &quot;*.dll&quot;,&quot;*.exe&quot; -Recurse
              write-host &quot;Validation result for : $($file.Name)&quot; -ForegroundColor Yellow
              write-host
              if ($dlls -eq $null) {write-host &quot;The $($file.Name) does not contain any binaries files&quot; -ForegroundColor Cyan}      
              foreach($dll in $dlls) 
              {
                  $goodString = &quot;&quot;
                  $badString = &quot;&quot;
                  if(((Get-AuthenticodeSignature -FilePath $dll).Status -eq &quot;Valid&quot;) -and ((Get-AuthenticodeSignature -FilePath $dll).SignerCertificate.Subject.Contains(&quot;company&quot;)))
                  { 
                  $goodString = &quot;The binary file: $($dll.Name) is signed by company , &quot;
                  }
                  else
                  {
                  $badString = &quot;The binary file: $($dll.Name) is not signed or not signed by company , &quot;
                  }
                  if ((($dll.VersionInfo.FileVersion) -eq &quot;1.0.0.0&quot;) -or (($dll.VersionInfo.FileVersion) -eq &quot;0.0.0.0&quot;))
                  {
                  $badString = $badString + &quot;The version of $($dll.Name) is: $($dll.VersionInfo.FileVersion)&quot;
                  }
                  else
                  {
                  $goodString = $goodString + &quot;The dll: $($dll.Name) version is: $($dll.VersionInfo.FileVersion)&quot;
                      
                  }
                  
                  write-host $badString -ForegroundColor Red
                  Write-Host $goodString -ForegroundColor Green
                  write-host
              }
               Write-Host
               Write-Host &quot;##################################################################################################################################################&quot; -ForegroundColor Yellow
               Write-Host
          }
          else
          {
              
              $dlls = Get-ChildItem $tempFolder -Include &quot;*.dll&quot;,&quot;*.exe&quot; -Recurse
              write-host &quot;Validation result for : $($file.Name)&quot; -ForegroundColor Yellow
              write-host
              if ($dlls -eq $null) {write-host &quot;The $($file.Name) does not contain any binaries files&quot; -ForegroundColor Cyan}      
              foreach($dll in $dlls) 
              {
                  $goodString = &quot;&quot;
                  $badString = &quot;&quot;
                  if(((Get-AuthenticodeSignature -FilePath $dll).Status -eq &quot;Valid&quot;) -and ((Get-AuthenticodeSignature -FilePath $dll).SignerCertificate.Subject.Contains(&quot;company&quot;)))
                  { 
                  $goodString = &quot;The binary file: $($dll.Name) is signed by company , &quot;
                  }
                  else
                  {
                  $badString = &quot;The binary file: $($dll.Name) is not signed or not signed by company , &quot; 
                  }
                  if ((($dll.VersionInfo.FileVersion) -eq &quot;1.0.0.0&quot;) -or (($dll.VersionInfo.FileVersion) -eq &quot;0.0.0.0&quot;))
                  {
                  $badString = $badString + &quot;The version of $($dll.Name) is: $($dll.VersionInfo.FileVersion)&quot;
                      
                  }
                  else
                  {
                  $goodString = $goodString + &quot;The dll: $($dll.Name) version is: $($dll.VersionInfo.FileVersion)&quot;
                      
                  }
                  
                  write-host $badString -ForegroundColor Red
                  Write-Host $goodString -ForegroundColor Green
                  write-host
              } 
              Write-Host  
              Write-Host &quot;##################################################################################################################################################&quot; -ForegroundColor Yellow 
              Write-Host           
          }
       }
       catch 
       {
              Write-Warning $_.Exception.Message
              continue
       }
       finally 
       {
                 Remove-Item $tempFolder -Force -Recurse
       }
      }
      elseif ($file -like &quot;*.vip&quot;) #vip
      {
       try 
       { 
          $zip = [System.IO.Compression.ZipFile]::ExtractToDirectory($file, $tempFolder)
          $dlls = Get-ChildItem $tempFolder -Include &quot;*.dll&quot;,&quot;*.exe&quot; -Recurse
          write-host &quot;Validation result for : $($file.Name)&quot; -ForegroundColor Yellow
          write-host
          if ($dlls -eq $null) 
          {
              write-host &quot;The $($file.Name) does not contain any dll&quot; -ForegroundColor Cyan
          }
          
          foreach($dll in $dlls) 
          {            
                  $goodString = &quot;&quot;
                  $badString = &quot;&quot;
                  if(((Get-AuthenticodeSignature -FilePath $dll).Status -eq &quot;Valid&quot;) -and ((Get-AuthenticodeSignature -FilePath $dll).SignerCertificate.Subject.Contains(&quot;company&quot;)))
                  { 
                  $goodString = &quot;The binary file: $($dll.Name) is signed by # , &quot;
                  }
                  else
                  {
                  $badString = &quot;The binary file: $($dll.Name) is not signed or not signed by company , &quot;    
                  }
                  if ((($dll.VersionInfo.FileVersion) -eq &quot;1.0.0.0&quot;) -or (($dll.VersionInfo.FileVersion) -eq &quot;0.0.0.0&quot;))
                  {
                  $badString = $badString + &quot;The version of $($dll.Name) is: $($dll.VersionInfo.FileVersion)&quot;  
                  }
                  else
                  {
                  $goodString = $goodString + &quot;The dll: $($dll.Name) version is: $($dll.VersionInfo.FileVersion)&quot;
                  }
                  
                  write-host $badString -ForegroundColor Red
                  Write-Host $goodString -ForegroundColor Green
                  write-host
          }  
                  Write-Host
                  Write-Host &quot;##################################################################################################################################################&quot; -ForegroundColor Yellow 
                  Write-Host
       }
       catch 
       {
              Write-Warning $_.Exception.Message
              continue
       }
       finally 
       {
                 Remove-Item $tempFolder -Force -Recurse
       }  
      }
       else #cab
      {
       try 
       { 
          #$zip = [System.IO.Compression.ZipFile]::ExtractToDirectory($file, $tempFolder)
          #need to extract cab
          $dlls = Get-ChildItem $tempFolder -Include &quot;*.dll&quot;,&quot;*.exe&quot; -Recurse
          if ($dlls -eq $null) 
          {
              write-host &quot;The $($file.Name) does not contain any dll&quot; -ForegroundColor Cyan
          }
          foreach($dll in $dlls) 
          {            
              if ((($dll.VersionInfo.FileVersion) -eq &quot;1.0.0.0&quot;) -or (($dll.VersionInfo.FileVersion) -eq &quot;0.0.0.0&quot;))
              {
                  Write-host &quot;The version of $($dll.Name) is: $($dll.VersionInfo.FileVersion) for: $($file.Name)&quot; -ForegroundColor red
              }
              else
              {
                  write-host &quot;Dll $($dll.Name) version is: $($dll.VersionInfo.FileVersion) for $($file.Name)&quot; -ForegroundColor Green
              }
              if ((($dll.VersionInfo.FileVersion) -eq &quot;1.0.0.0&quot;) -or (($dll.VersionInfo.FileVersion) -eq &quot;0.0.0.0&quot;))
                  {
                      Write-host &quot;The version of $($dll.Name) is: $($dll.VersionInfo.FileVersion) for: $($file.Name)&quot; -ForegroundColor red 
                  }
                  else
                  {
                      write-host &quot;Dll $($dll.Name) version is: $($dll.VersionInfo.FileVersion) for $($file.Name)&quot; -ForegroundColor Green
                  }
          }   
       }
       catch 
       {
              Write-Warning $_.Exception.Message
              continue
       }
       finally 
       {
                 Remove-Item $tempFolder -Force -Recurse
       }  
      }
      }
  
  write-host &quot;The scan was ended&quot;
  Read-Host &quot;Press any key to exit&quot; 
  </code></pre>