2

I use PowerShell script to uninstall software, remove services and delete installation folder. Full clean up. This software has core app and 11 addins. So I use this code for addins:

    $appAddIns = @(Get-WmiObject -Class Win32_Product | Where-Object { $_.Name -match "SE0008*" }) 
foreach ($appAddIn in $appAddIns) 
    {
    Write-Host "Uninstalling: " $appAddIn.Name
    $appAddIn.Uninstall() | out-null
    }

But it's terribly slow to even start the script. I run it, and it's just blank. My colleague at work didn't use my script because after 10 seconds he assumed that it doesn't work and terminated it.

Is there any way to write it better, or just add:

Write-Host "Sit and wait you impatient bastard"

at the beginning?

Diodak
  • 80
  • 8
  • 3
    Do not use `Win32_Product` for this. https://gregramsey.net/2012/02/20/win32_product-is-evil/ . See http://stackoverflow.com/questions/25268491/alternative-to-win32-product – restless1987 Jan 02 '17 at 13:52

3 Answers3

4

win32_product is slow ,you can utilize this registry path (HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall) to get the uninstallation command and run it

ClumsyPuffin
  • 3,909
  • 1
  • 17
  • 17
2

You could use Write-Progress and then update it with the name of the program you are uninstalling and a calculated percentage based on the number of programs being uninstalled.

Here is an example:

Write-Progress -Activity "Uninstalling programs..."

for ($i = 1; $i -le 5; $i++) {
    Write-Progress -Activity "Uninstalling programs..." -Status "Program $i" -PercentComplete ($i / 5 * 100)
    Start-Sleep -Seconds 1
}
kaspermoerch
  • 16,127
  • 4
  • 44
  • 67
2

Win32_product is broken and should not be used (even Microsoft wrote some articles about this broken WMI class). Besides it being very slow, it also causes problems with the current installed MSI packages since it forces a re-register on all registered MSI packages. The easiest way to uninstall software is nowadays Powershell Desired State Configuration (note that you need at least Windows 8.1 for this). With DSC you can also change Service behaviour, remove files, install / uninstall MSI packages, run Powershell scripts etc.

bluuf
  • 936
  • 1
  • 6
  • 14
  • Thank you for this information! We use Win 7 so Powershell Desired State Configuration won't help here. We use a lot of MSI packages so I'm withdrawing this script right now. – Diodak Jan 02 '17 at 14:09