在WSUS 3中使用powershell列出已取代的更新

时间:2013-10-22 15:57:35

标签: powershell

我正在尝试自动化管理WSUS报告的过程。我成功了 I)报告我批准的WSUS控制台更新。 II)为替换

运行清理过程

因此,我用来列出已批准的更新更新的脚本是:

$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$updatescope.ApprovedStates = [Microsoft.UpdateServices.Administration.ApprovedStates]::LatestRevisionApproved
$updatescope.FromArrivalDAte = [datetime]"10/08/2013"
$wsusgroup = $wsus.GetComputerTargetGroups() | Where {$_.Name -eq "PCM_WSUS_spec"}
$updatescope
$updatescope.gettype()
$updatescope.count
$updateScope.ApprovedComputerTargetGroups.add($wsusgroup)
$wsus.GetUpdates($updatescope) | Select KnowledgebaseArticles,Title
$Updates = $wsus.GetUpdates($updatescope) | Select KnowledgebaseArticles

我真正需要的是一个基于aboce列表取代的更新列表的函数;在给定日期之后获得批准的更新。

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

要构建已取代更新的列表,您需要了解当前更新。已取代的更新将作为与当前更新关联的UpdateID列表进行维护。 (取代更新列表是通过向后遍历该列表构建的。)

在实际的XML包中,它看起来像这样:

<sdp:SupersededPackages xmlns:sdp="http://schemas.microsoft.com/wsus/2005/04/CorporatePublishing/SoftwareDistributionPackage.xsd">
  <sdp:PackageID>b87cc8c1-b03d-4548-aa53-f0138ec6e2a3</sdp:PackageID>
  <sdp:PackageID>7d8fcd7b-49d1-440d-8140-d6c33ce2cb80</sdp:PackageID>
  <sdp:PackageID>76f68136-436f-42a5-9029-560b23702416</sdp:PackageID>
  <sdp:PackageID>64b8c9d0-ecbc-4711-90de-b190d2ee7ee1</sdp:PackageID>
  <sdp:PackageID>6bd77c33-1b2d-450d-91c6-259e101e57bb</sdp:PackageID>
  <sdp:PackageID>94642c22-d70e-45b8-a70f-c09b86e2c4f5</sdp:PackageID>
</sdp:SupersededPackages>

但我不知道它是如何通过API实际访问的(如果可能的话),或者在数据库模式中找到它的位置。

答案 1 :(得分:0)

我使用以下内容获得了一个列表:

 '[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
$WSUS = [Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer('wsupdates',$false,80) 
#creating the update scope. Different parameters can be used each time for different reports needed
$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
$updatescope.ApprovedStates = [Microsoft.UpdateServices.Administration.ApprovedStates]::LatestRevisionApproved
$updatescope.FromArrivalDAte = [datetime]"10/08/2013"
$wsusgroup = $wsus.GetComputerTargetGroups() | Where {$_.Name -eq "PCM_WSUS_spec"}
$updateScope.ApprovedComputerTargetGroups.add($wsusgroup)
$updatescope
$updates = $wsus.GetUpdates($updatescope) | Select Title,UpdateClassificationTitle,SupersededUpdates | Sort Title |Export-csv 'C:\WSUS\test_approved.csv' -notype
$updates = $wsus.GetUpdates($updatescope) 
$updates 



$updates | ForEach-Object  {
$temp =$_
Write-Output ' temp is'
$temp
$temp | Select Title| Export-CSV 'C:\wsus\superseded.csv' -Append -Notype -Force
$SupersededOnes = $_.GetRelatedUpdates(([Microsoft.UpdateServices.Administration.UpdateRelationship]::UpdatesSupersededByThisUpdate)) |Select Title
Write-Output 'after finding out superseded'
$SupersededOnes
Start-Sleep 8
$SupersededOnes | Export-CSV 'C:\wsus\superseded.csv' -Append -Notype -Force
}' 

我的问题是,除了关联取代更新之外,我还需要将其替换为已批准的下方。