CLC
Well-Known Member
- Reaction score
- 320
- Location
- Central Minnesota USA
EDIT: Script provided by @pcpete  , Thanks!!
	
	
	
		
				
			
		Code:
	
	#this script has 4 main parts: first it checks that you are running this from an admin console;
#it checks if the update is installed; third, if it is installed it removes it; forth
#it will hide the update so it does not reinstall
#the only option the needs to be set is the hotfixid you want removed as set below
#it is currently set to KB3035583, but can be change to check for any hotfix
$hotfixid = "kb3035583"
# this first funciton checks if you are running from an admin console
function check-admin{
    $User = [Security.Principal.WindowsIdentity]::GetCurrent()
    $Role = (New-Object Security.Principal.WindowsPrincipal $user).IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
    if($Role -eq $false){
        write-host "-you will need run this script from an elevated powershell console, the script will now exit"
    }
    $result = $role
    $result
}
#this function checks if the update is installed. if installed it returns $True
function check-installed {
    #we disable error messages for this part of the function. since the logic depends on creating a possible error and it is expected
    $ErrorActionPreference = "silentlycontinue"
    write-host "-checking if $hotfixid is currently installed"
    $isthere = (Get-HotFix $hotfixid)
    if ($isthere.hotfixid -eq $hotfixid){
        #if installed it will return $True
        $result = $true
    }
    else {
        #if not installed it will return $False
        $result = $false
    }
    $result
}
#this is the function that removes the hotfix
function remove-hotfix{
    $hotfixformat = $hotfixid.substring(0,2)+":"+$hotfixid.substring(2)
    wusa /uninstall /$hotfixformat /quiet /norestart
}
#used code from http://www.powershellmagazine.com/2014/03/19/how-to-view-and-restore-hidden-windows-updates-with-powershell/ for the next two functions
function find-hotfixes{ 
    try {
        Write-host "-querying Windows update"
        $Session = New-Object -ComObject Microsoft.Update.Session     
        $Searcher = $Session.CreateUpdateSearcher()     
        $Criteria = "IsInstalled=0 and DeploymentAction='Installation' or IsPresent=1 and DeploymentAction='Uninstallation' or IsInstalled=1 and DeploymentAction='Installation' and RebootRequired=1 or IsInstalled=0 and DeploymentAction='Uninstallation' and RebootRequired=1"   
        $SearchResult = $Searcher.Search($Criteria)   
        $SearchResult.Updates
    } catch {
        Write-Warning -Message "-Failed to query Windows Update because $($_.Exception.Message)"
    }
}
Function Set-WindowsHiddenUpdate {
    [Cmdletbinding()]
    Param(
        [Parameter(ValueFromPipeline=$true,Mandatory=$true)]
        [System.__ComObject[]]$Update,
        [Parameter(Mandatory=$true)]
        [boolean]$Hide
    )
    Process {
        $Update | ForEach-Object -Process {
            if (($_.pstypenames)[0] -eq 'System.__ComObject#{c1c2f21a-d2f4-4902-b5c6-8a081c19a890}') {
                try {
                    $_.isHidden = $Hide
                    Write-Host "-hiding $($_.Title)"
                }
                catch {
                    Write-Host "-Failed to perform action because $($_.Exception.Message)"
                }
            } else {
                Write-Warning -Message "Ignoring object submitted"
            }
        }
    }
}
#this first part uses check-admin function to see if the script can continue
if (check-admin){
    #first checks to see if hotfix is installed, if it is it removes it
    if (check-installed){
        write-host "-currently removing $hotfixid"
        remove-hotfix
    }
    else{
        write-host "-hotfix $hotfixid does not appear to be installed"
    }
    find-hotfixes | Where-Object {$_.title -match $hotfixid}  |  Set-WindowsHiddenUpdate -hide $true -Verbose
}
			
				Last edited: 
			
		
	
								
								
									
	
								
							
							 
	 
 
		 
 
		 
 
		 
 
		
 
 
		 
 
		 
 
		
 
 
		 
 
		 
 
		 
 
		 
 
		