Uncategorized

test

By October 15, 2021October 16th, 2021No Comments

#=============================================================================================================================
#
# 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"
$logpath = "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 -logpath $logpath -message "$hotfixID detected on system"
        #detect architecture
        write-log INFO -logpath $logpath -message "Actual processor architecture = $env:PROCESSOR_ARCHITECTURE"
        if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64"){
            write-log INFO -logpath $logpath -message "Processor architecture condition pass on x64"
            write-log INFO -logpath $logpath -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 -logpath $logpath -message "Install exit code = $?"
            write-log INFO -logpath $logpath -message "Trigger restart on 60 min, display message"
            shutdown -r -f -t 3600
        }
        if ($env:PROCESSOR_ARCHITECTURE -eq "x86"){
            write-log INFO -logpath $logpath -message "Processor architecture condition pass on x86"
            write-log INFO -logpath $logpath -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 -logpath $logpath -message "Install exit code = $?"
            write-log INFO -logpath $logpath -message "Trigger restart on 60 min, display message"
            shutdown -r -f -t 3600
        }    
    }
    else {            
    write-log warn -logpath $logpath -message "Problematic hotfix not found - return exit 1, detection methode failed"
    exit 1
    }            
}
Uninstall-Hotfix -HotfixID $HotfixID

#Impacted OS = 10.0.18363 (update 10.0.18363.1854)
$OSbuild = (Get-CimInstance Win32_OperatingSystem).version
if($OSbuild -eq "10.0.18363"){
    #Scipt designed  by Jonathan Clanet (Cortex GH)#
    $Installedhotfix = Get-HotFix
    $Installedhotfix.HotFixID
    #Check if hotfixe is installed ($True = yes, $False = no)
    $CheckIfHotfixIsInstalled = $Installedhotfix.HotFixID -contains "KB5006667"
    try{
        if ($CheckIfHotfixIsInstalled -eq $false){
            write-host "Update not found, all rights"
            exit 0  
        }
        else {
            write-host "Update found, need to be uninstall"
            exit 1}
 
    }
    catch{
        $errMsg = $_.Exception.Message
        write-host $errMsg
        exit 1
    }
}
else {#Other OS exit
     exit 1
     }

Leave a Reply