Delete unused .msi and .msp files.

Powershell script to find and delete orphaned items in C:\Windows\Installer folder. It can be very helpful especially on smaller SSD drives, where you never have enough free space.Basically it is Heath Stewart's old VB Script(WiMsps.vbs) ported to Powershell with a bit added func

WInstCleaner.ps1
 
 
 
 
 
(0)
2,608 times
Add to favorites
Applications
2/7/2019
E-mail Twitter del.icio.us Digg Facebook
  • Not working
    3 Posts | Last post December 13, 2019
    • I am also encountering the same problem as reported by others below. When executing I get the error: Method invocation failed because [System.__ComObject] does not contain a method named 'Products'.
      At C:\Temp\WInstCleaner.ps1:22 char:1
      + $Products = $Installer.Products()
    • Sadly I have nowhere to test it, but I think the problem is in Windows installer version there.
      
      https://docs.microsoft.com/en-us/windows/desktop/msi/installer-object
      specifically:
      https://docs.microsoft.com/en-us/windows/desktop/msi/installer-products
      
      It lists requirement as follows: "Windows Installer 5.0 on Windows Server 2012, Windows 8, Windows Server 2008 R2 or Windows 7. Windows Installer 4.0 or Windows Installer 4.5 on Windows Server 2008 or Windows Vista. Windows Installer on Windows Server 2003 or Windows XP"
      
    • Working on windows 7:
      
      $Installer = New-Object -ComObject WindowsInstaller.Installer
      $Type = $Installer.GetType()
      $Products = $Type.InvokeMember('Products', [System.Reflection.BindingFlags]::GetProperty, $null, $Installer, $null)
      
  • Great Script, Not for PS 4
    1 Posts | Last post May 07, 2019
    • Works great with PowerShell 5, not with PowerShell 4 on Win 2012 R2.  It doesn't like the "$Installer.Products()" part.  Would upgrade but I have about 50 servers on this version, several in prod.  
  • Issue with ending IF statements
    2 Posts | Last post February 02, 2019
    • To anyone not getting any output or activity from this script, it's because the two IF statements at the end are supposed to be checking to make sure that the detected MSP's/MSI's are not equal to 0 before calling for their removal, but the IF condition is backwards so it's only calling for the removal if there are NOT any files found.
      
      Simply change the following at the end of the script:
      
      #Use the function to compare found data with the files in the C:\windows\installer directory.
      If ( $PatchesLocation.Count -eq 0)
      {
          Clean-Up -FileType "msp" -Data $PatchesLocation
      }
      If ( $InstallersLocation.Count -eq 0)
      {
          Clean-Up -FileType "msi" -Data $InstallersLocation
      }
      
      
      to this:
      
      #Use the function to compare found data with the files in the C:\windows\installer directory.
      If ( $PatchesLocation.Count -ne 0)
      {
          Clean-Up -FileType "msp" -Data $PatchesLocation
      }
      If ( $InstallersLocation.Count -ne 0)
      {
          Clean-Up -FileType "msi" -Data $InstallersLocation
      }
      
      
      Then it will run as expected.
      
    • Yes, that is correct, thanks for pointing it out. I modified the script also, so when you download now, you will get working version.