powershell 卸载修补程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 卸载修补程序相关的知识,希望对你有一定的参考价值。

Function Check-IsPatchInstalled {
    PARAM (
       [Parameter(Mandatory=$false,ValueFromPipeline=$false)][String]$computer = "127.0.0.1",
       [Parameter(Mandatory=$true,ValueFromPipeline=$false)][String]$id
    )
 
    $patches = Get-WmiObject -Class Win32_QuickFixEngineering -ComputerName $computer | select description,hotfixid,installedon
 
    if ($patches | ? { $_.Hotfixid -like $id }) {
        return $true
    } else {
        return $false
    }
}

Function LogWrite
{
	Param ([string]$logString)

	Add-Content -Path $logFile -Value ($(get-date -f MM-dd-yyyy_HH_mm_ss) + ": " + $logString)
}

# KB to uninstall (zonder KB ervoor)
$UninstallKB = "3008923"

# Location of the Log File
$logFile = "C:\Logs\KB" + $UninstallKB + "_Uninstall.log"

# Check if KB is installed on the local computer. If so, uninstall it.
If (Check-IsPatchInstalled -id "KB$UninstallKB) {
	# Write to the Log File
	LogWrite "Start to uninstall "KB$UninstallKB"
	# Uninstall Hotfix
	& wusa.exe /kb:$UninstallKB /uninstall /quiet /norestart
	#cmd.exe /c wusa.exe /kb:$UninstallKB /uninstall /quiet /norestart
	
	# Voor SCCM, gebruik SysNative
	#& %windir%\SysNative\wusa.exe /kb:$UninstallKB /uninstall /quiet /norestart
	
	LogWrite "Uninstalled KB$UninstallKB"
}
Else {
	# Write to the Log File
	LogWrite "KB$UninstallKB Not found"
}

以上是关于powershell 卸载修补程序的主要内容,如果未能解决你的问题,请参考以下文章

powershell 获取已安装日期的修补程序

powershell Windows修补程序删除

powershell Windows修补程序删除

powershell 检查是否安装了修补程序

powershell 安装Windows修补程序

powershell 列出已安装的修补程序。