Windows: Script to uninstall all Hotfixes and Updates

Hi,

here is a “oneliner” to uninstall all Windows Update at once. They were deinstalled in order from the highest to the lowest KB Number which increases speed of the remove process(Latest fix first).

PS C:\>  Get-WmiObject -query "Select HotFixID  from Win32_QuickFixengineering" | sort-object -Descending -Property HotFixID|%{
	$sUpdate=$_.HotFixID.Replace("KB","")
 	write-host ("Uninstalling update "+$sUpdate);
	& wusa.exe /uninstall /KB:$sUpdate /quiet /norestart;
	# while((Get-Process "wusa" -ErrorAction SilentlyContinue).Count -ge 1){start-sleep 1}
        # Waiting until an existing Hotfix installation finish. Improved by Paul T
        Wait-Process wusa
        Start-Sleep -s 1
}

And extended to deinstall a defined number of fixes

$iFixCount=20
Get-WmiObject -query "Select HotFixID  from Win32_QuickFixengineering" | sort-object -Descending -Property HotFixID|%{
	$sUpdate=$_.HotFixID.Replace("KB","")
 	write-host ("Uninstalling update "+$sUpdate);
	& wusa.exe /uninstall /KB:$sUpdate /quiet /norestart;
	# while((Get-Process "wusa" -ErrorAction SilentlyContinue).Count -ge 1){start-sleep 1}
        # Waiting until an existing Hotfix installation finish. Improved by Paul T
        Wait-Process wusa
        Start-Sleep -s 1
	$iFixCount--
	if($iFixCount -le 0){
		break
	}
 }
shutdown /t 0 /r /f

Have fun

Michael

Advertisment to support michlstechblog.info

Add a comment »3 comments to this article

  1. Thanks for this.

    The first script to uninstall all updates didn’t quite work for me. It didn’t wait for the wusa process to finish and carried on trying to do the others while one was already running.

    I fixed this by just removing the line:
    while((Get-Process “wusa” -ErrorAction SilentlyContinue).Count -ge 1){start-sleep 1}

    and adding in the following 2 lines in its place:
    Wait-Process wusa
    Start-Sleep -s 1

    So the complete script that worked for me as expected was:

    Get-WmiObject -query “Select HotFixID from Win32_QuickFixengineering” | sort-object -Descending -Property HotFixID|%{
    $sUpdate=$_.HotFixID.Replace(“KB”,””)
    write-host (“Uninstalling update “+$sUpdate);
    & wusa.exe /uninstall /KB:$sUpdate /quiet /norestart;
    Wait-Process wusa
    Start-Sleep -s 1
    }

    Reply

    • Hi Paul T,

      I replaced the part with your lines of code.

      Thank you Michael

      Reply

  2. very very useful,
    Thanks a lot.

    Reply

Time limit is exhausted. Please reload CAPTCHA.

Original Theme by Schiy · Powered by WordPress