powershell Windows修补程序删除
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell Windows修补程序删除相关的知识,希望对你有一定的参考价值。
#Run - Get-Cluster CLUSTERNAME | Get-VM | Select Name | Sort Name | Export-Csv ./CLUSTERNAME.csv -NoTypeInformation
$clusterVMs = Import-Csv '.\ASMCL06.csv'
$KB = "KB2982791"
$KBNumber = $KB.Replace("KB", "")
$RemovalCommand = "wusa.exe /uninstall /kb:$KBNumber /quiet /norestart"
$Domain = "corp.local"
$report = @()
$clusterVMs | % {
$computerName ="$($_.Name).$($Domain)"
$reportObject = New-Object PSObject
Add-Member -InputObject $reportObject -MemberType NoteProperty -Name Name -Value $computerName
Write-Host "Processing $computername " -NoNewLine
try {
$result = Invoke-Command -ComputerName $computerName -ScriptBlock {
if ((Get-Hotfix -Id $Using:KB -ErrorAction SilentlyContinue)){
Invoke-Expression -Command $Using:RemovalCommand
while ($true) {
Start-Sleep 3
if ((Get-Process | Where-Object {$_.name -eq "wusa"}).Count -eq 0 -or (Get-Process | Where-Object {$_.name -eq "wusa"}).Count -eq $null){
break
}
}
if (!(Get-Hotfix -Id $Using:KB -ErrorAction SilentlyContinue)){
Write-Host "|KB Removed|" -ForegroundColor GREEN
$result = "KB Removed"
}
}
else {
Write-Host "|Could not find KB|" -ForegroundColor GREEN
$result = "Could not find KB"
}
#Return result here
$result
} -ErrorAction Stop
Add-Member -InputObject $reportObject -MemberType NoteProperty -Name KBRemoval -Value $result
}
catch [Exception] {
Write-Host "|Failed!|" -ForegroundColor RED
Add-Member -InputObject $reportObject -MemberType NoteProperty -Name KBRemoval -Value $_.Exception.Message
}
#Add each new object to the report array
$report += $reportObject
}
#Export the array to CSV
$report | Export-Csv -Path "./hotfixReport-$(Get-Date -Format ttMMyyyHHmmSS).csv" -NoTypeInformation
以上是关于powershell Windows修补程序删除的主要内容,如果未能解决你的问题,请参考以下文章
powershell 安装Windows修补程序
powershell PowerShell:搜索修补程序。
powershell 获取已安装日期的修补程序
powershell 检查是否安装了修补程序
powershell 卸载修补程序
powershell 列出已安装的修补程序。