I've been combining two of the scripts I have found relating to windows
update services, basically I've come to a stop with passing a target group to
the computer scope section of the following script. I want the count of
approved updates by computers in a WSUS container.
It is the $computerscope variable I am having trouble understanding:
$updates = $wsus.GetSummariesPerUpdate($updateScope, $computerScope);
Here's the script, any help would be greatly appreciated.
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null
$wsus =
[Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
$updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope;
$updateScope.ApprovedStates =
[Microsoft.UpdateServices.Administration.ApprovedStates]::LatestRevisionApproved;
$updateScope.UpdateSources =
[Microsoft.UpdateServices.Administration.UpdateSources]::MicrosoftUpdate;
function ProcessGroup {
param($parentGroup);
#depth first, so you delete the deepest group first
$childCount = 0;
$parentGroup.GetChildTargetGroups() | foreach-object {
$processCount = ProcessGroup($_);
$childCount = $childCount + $processCount;
}
$count = 0;
$count = $parentGroup.GetComputerTargets($false).Count;
$totalCount = $count + $childCount;
if ($parentGroup.Id -eq
[Microsoft.UpdateServices.Administration.ComputerTargetGroupId]::AllComputers) { }
elseif ($parentGroup.Id -eq
[Microsoft.UpdateServices.Administration.ComputerTargetGroupId]::UnassignedComputers) { }
elseif ($parentGroup.Id -eq
[Microsoft.UpdateServices.Administration.ComputerTargetGroupId]::WindowsProductIdValidated) {}
else {
echo "--------------GROUP--------------------------" | out-file
E:\reps\groups2.txt -append
$parentGroup.Name | out-file E:\reps\groups2.txt -append
echo $totalCount | out-file E:\reps\groups2.txt -append
$ALL = $parentgroup.GetComputerTargets();
$everyone = $ALL | foreach-object {$_.FullDomainName | Out-file
-append E:\reps\groups2.txt}
$computerScope = new-object
Microsoft.UpdateServices.Administration.ComputerTargetScope;
$computerScope.ComputerTargetGroups =
[Microsoft.UpdateServices.Administration.ComputerTargetGroupId]::$parentGroup.Id;
$updatesFailed = $updatesNeeded = $updatesUpToDate = 0;
$updates = $wsus.GetSummariesPerUpdate($updateScope, $computerScope);
$updates | foreach-object {
if ($_.FailedCount) {
$updatesFailed++;
}
elseif ($_.DownloadedCount -or $_.InstalledPendingRebootCount -or
$_.NotInstalledCount) {
$updatesNeeded++;
}
elseif (!$_.UnknownCount) {
$updatesUpToDate++;
}
}
#$parentgroup.GetComputerTargets() | gm | where {$_.membertype
-eq "property" -AND $._typename -like "*FullDomainName*"} | out-file
E:\reps\groups2.txt -append
echo "total approved = " $updates.count | out-file
E:\reps\groups2.txt -append
echo "--------------END--------------------------" | out-file
E:\reps\groups2.txt -append
}
return $totalCount;
}
$AllComputersGroup =
$wsus.GetComputerTargetGroup([Microsoft.UpdateServices.Administration.ComputerTargetGroupId]::AllComputers);
ProcessGroup($AllComputersGroup) | out-null;
Microsoft.UpdateServices.Administration.ComputerTargetScope
to make the $computerScope only the servers located in a target WSUS container
$updates = $wsus.GetSummariesPerUpdate($updateScope, $computerScope);
Just can't get my head round the syntax of GetSummariesPerUpdate as the
above is global
ComputerTargetScope is used by specifying ComputerTargetGroups by ID (if
that's what you asked about)
Martin
"Jason Ferguson" <JasonF...@discussions.microsoft.com> wrote in message
news:282AC0CA-C080-4268...@microsoft.com...
##################################################################################################
######### Script to report on WSUS computer target groups, exports by group
#####################
######### the number of servers and number of patches selected for install
#####################
######### on the target group. Secondly the script outputes a list of
#####################
######### of the updates set for install to a second file for analysis.
#####################
######### Adapted from the delete empty containers script.
#####################
##################################################################################################
####### This loads the update services asembly and sets $wsus to the update
server
[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | out-null
$wsus =
[Microsoft.UpdateServices.Administration.AdminProxy]::GetUpdateServer();
####### The update scope is set here for approved revisions # out latest
revisions for all updates
####### I am interested in looking at approved updates
$updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope;
$updateScope.ApprovedStates =
[Microsoft.UpdateServices.Administration.ApprovedStates]::LatestRevisionApproved;
$updateScope.UpdateSources =
[Microsoft.UpdateServices.Administration.UpdateSources]::MicrosoftUpdate;
$updateScope.UpdateApprovalActions =
[Microsoft.UpdateServices.Administration.UpdateApprovalActions]::All;
####### Sets the locations for the output report files
####### there is probably a more elegant way to achieve this!
$groupfilename1 = "E:\reps\WSUSgroupsummary" #set the output file name and
path
$groupfilename2 = [DateTime]::UtcNow.ToShortDateString() | % {
$_.split("/")[0] }
$groupfilename3 = [DateTime]::UtcNow.ToShortDateString() | % {
$_.split("/")[1] }
$groupfilename4 = [DateTime]::UtcNow.ToShortDateString() | % {
$_.split("/")[2] }
$groupsumfile =
$groupfilename1+""+$groupfilename2+"-"+$groupfilename3+"-"+$groupfilename4+".csv";
$title1 = "WSUS Group Report for
"+$groupfilename2+"-"+$groupfilename3+"-"+$groupfilename4+",";
$title1 | out-file $groupsumfile;
echo "Group,No Servers,Install Count,Inherit Count," | out-file
$groupsumfile -append;
$instfilename1 = "E:\reps\WSUSinstallsummary" #set the output file name and
path
$installreport =
$instfilename1+""+$groupfilename2+"-"+$groupfilename3+"-"+$groupfilename4+".csv";
$title2 = "WSUS Installed Patch Report for
"+$groupfilename2+"-"+$groupfilename3+"-"+$groupfilename4+",";
$title2 | out-file $installreport;
echo "Group,Update,Arrival Date,Creation Date," | out-file $installreport
-append;
####### The function for processing the all computer group is called at the
bottom!
function ProcessGroup {
param($parentGroup);
### This processes each child group of the target group $parentgroup in
this script is
### set at the bottom to be Allcomputer group
### each sub group will be processed from here on as $parentgroup
$childCount = 0;
$parentGroup.GetChildTargetGroups() | foreach-object {
$processCount = ProcessGroup($_);
$childCount = $childCount + $processCount;
}
$count = 0;
$count = $parentGroup.GetComputerTargets($false).Count;
$totalCount = $count + $childCount;
##### Set high so all groups are processed and then exclude default
groups and any other groups
##### you dont want to report on such as desktops in my case
if ($totalCount -lt 1000000) {
if ($parentGroup.Id -eq
[Microsoft.UpdateServices.Administration.ComputerTargetGroupId]::AllComputers) { }
elseif ($parentGroup.Id -eq
[Microsoft.UpdateServices.Administration.ComputerTargetGroupId]::UnassignedComputers) { }
elseif ($parentGroup.Id -eq
[Microsoft.UpdateServices.Administration.ComputerTargetGroupId]::WindowsProductIdValidated) {}
elseif ($parentGroup.Id -eq
[Microsoft.UpdateServices.Administration.ComputerTargetGroupId]::Desktops) {}
else {
######## From here on we are performing the reporting for each sub group
#echo "--------------GROUP--------------------------" |
out-file $groupsumfile -append
$thegroupname = $parentGroup.Name
$servercount = $totalCount
$ALL = $parentgroup.GetComputerTargets();
$serverslist = $ALL | foreach-object {$_.FullDomainName}
$computerScope = new-object
Microsoft.UpdateServices.Administration.ComputerTargetScope;
$updatesFailed = $updatesNeeded = $updatesUpToDate =
$notapp = $installed = 0;
$updates = $wsus.GetSummariesPerUpdate($updateScope,
$computerScope);
$updatesFailed = $updatesNeeded = $updatesUpToDate =
$approvedcounter = 0;
$target = $parentGroup.id.Guid;
$targetgrp = $wsus.getcomputertargetgroup("$target");
$approvedupdates =
$targetgrp.GetSummaryPerUpdate($updateScope);
echo
"--------------------------------------------------------" $targetgrp.name |
out-file E:\reps\nameinst.txt -append;
$inhercnt = $instcnt = 0;
$theupdates = $wsus.GetUpdates($updateScope);
$theupdates | foreach-object {
$update = $_
$targetgrp | foreach {
$group = $_
$range =
$update.GetUpdateApprovals($group)[0].Action;
if ($range -eq $null){$inhercnt++};
if ($range -match "Install"){$instcnt++;
$thegroupname+","+$update.Title+","+$update.ArrivalDate+","+$update.CreationDate+"," | out-file $installreport -append};
}
}
$repdata =
$thegroupname+","+$servercount+","+$instcnt+","+$inhercnt+",";
$repdata | out-file $groupsumfile -append;
}
}
return $totalCount;
}
#### This is the start of the script and sets the AllComputers group as the
target start group, the function
#### ProcessGroup will process each child group of this target group
echo "Group Report" | out-file E:\reps\groups2.txt