#============================================================================================================================= # # Script Name: UninstallHotfix.ps1 # Description: Uninstall scpecific KB updates # Notes: inspired by https://techibee.com/powershell/powershell-uninstall-windows-hotfixesupdates/1084 # http://download.windowsupdate.com/c/msdownload/update/software/secu/2021/10/windows10.0-kb5006667-x64_202bc0d5c7a8ffe626ff09ddb3b3f81e757a9d37.msu #============================================================================================================================= $HotfixID = "KB5006667" $logfile = "C:\Windows\debug\UninstallHotfi$HotfixID.log" #Add log fuction Function Write-Log { [CmdletBinding()] Param( [Parameter(Mandatory=$False)] [ValidateSet("INFO","WARN","ERROR","FATAL","DEBUG")] [String] $Level = "INFO", [Parameter(Mandatory=$True)] [string] $Message, [Parameter(Mandatory=$False)] [string] $logfile ) $Stamp = (Get-Date).toString("yyyy/MM/dd HH:mm:ss") $Line = "$Stamp $Level $Message" If($logfile) { Add-Content $logfile -Value $Line } Else { Write-Output $Line } } #Add Uninstall hotfix fuction function Uninstall-Hotfix { [cmdletbinding()] param( [string] $HotfixID ) $hotfixes = Get-WmiObject -Class Win32_QuickFixEngineering | select hotfixid if($hotfixes -match $hotfixID) { write-log INFO -logfile $logfile -message "$hotfixID detected on system" #detect architecture write-log INFO -logfile $logfile -message "Actual processor architecture = $env:PROCESSOR_ARCHITECTURE" if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64"){ write-log INFO -logfile $logfile -message "Processor architecture condition pass on x64" write-log INFO -logfile $logfile -message "Trying to unsinstall package Package_for_RollupFix~31bf3856ad364e35~amd64~~18362.1854.1.5" Try{Remove-WindowsPackage -Online -PackageName "Package_for_RollupFix~31bf3856ad364e35~amd64~~18362.1854.1.5" -norestart} Catch {write-log warn -logfile $logfile -message "Error = $Error[0].Exception"} Remove-WindowsPackage -Online -PackageName "Package_for_RollupFix~31bf3856ad364e35~amd64~~18362.1854.1.5" -norestart write-log INFO -logfile $logfile -message "Install exit code = $?" write-log INFO -logfile $logfile -message "Trigger restart on 60 min, display message" shutdown -r -f -t 3600 } if ($env:PROCESSOR_ARCHITECTURE -eq "x86"){ write-log INFO -logfile $logfile -message "Processor architecture condition pass on x86" write-log INFO -logfile $logfile -message "Trying to unsinstall package Package_for_RollupFix~31bf3856ad364e35~amd64~~18362.1854.1.5" Remove-WindowsPackage -Online -PackageName "Package_for_RollupFix~31bf3856ad364e35~amd64~~18362.1854.1.5" -norestart write-log INFO -logfile $logfile -message "Install exit code = $?" write-log INFO -logfile $logfile -message "Trigger restart on 60 min, display message" shutdown -r -f -t 3600 } } else { write-log warn -logfile $logfile -message "Problematic hotfix not found - return exit 1, detection methode failed" exit 1 } } Uninstall-Hotfix -HotfixID $HotfixID