Skip to content

Instantly share code, notes, and snippets.

@AdilHindistan
Last active May 15, 2020 13:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdilHindistan/9938810 to your computer and use it in GitHub Desktop.
Save AdilHindistan/9938810 to your computer and use it in GitHub Desktop.
#AH - AdilHindistan - 2014-02-04 WSUS Update Scopes
## We are trying to find out updates that are needed on Computers but we have NOT approved yet
## WSUS Update Scope
$UpdateScope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
D:\> $updateScope |Get-Member -MemberType property
TypeName: Microsoft.UpdateServices.Administration.UpdateScope
Name MemberType Definition
---- ---------- ----------
ApprovedComputerTargetGroups Property Microsoft.UpdateServices.Administration.ComputerTargetGroupCollection ApprovedComputerTargetGroups {get;}
ApprovedStates Property Microsoft.UpdateServices.Administration.ApprovedStates ApprovedStates {get;set;}
Categories Property Microsoft.UpdateServices.Administration.UpdateCategoryCollection Categories {get;}
Classifications Property Microsoft.UpdateServices.Administration.UpdateClassificationCollection Classifications {get;}
ExcludedInstallationStates Property Microsoft.UpdateServices.Administration.UpdateInstallationStates ExcludedInstallationStates {get;set;}
ExcludeOptionalUpdates Property bool ExcludeOptionalUpdates {get;set;}
FromArrivalDate Property datetime FromArrivalDate {get;set;}
FromCreationDate Property datetime FromCreationDate {get;set;}
IncludedInstallationStates Property Microsoft.UpdateServices.Administration.UpdateInstallationStates IncludedInstallationStates {get;set;}
IsWsusInfrastructureUpdate Property bool IsWsusInfrastructureUpdate {get;set;}
TextIncludes Property string TextIncludes {get;set;}
TextNotIncludes Property string TextNotIncludes {get;set;}
ToArrivalDate Property datetime ToArrivalDate {get;set;}
ToCreationDate Property datetime ToCreationDate {get;set;}
UpdateApprovalActions Property Microsoft.UpdateServices.Administration.UpdateApprovalActions UpdateApprovalActions {get;set;}
UpdateApprovalScope Property Microsoft.UpdateServices.Administration.UpdateApprovalScope UpdateApprovalScope {get;set;}
UpdateSources Property Microsoft.UpdateServices.Administration.UpdateSources UpdateSources {get;set;}
UpdateTypes Property Microsoft.UpdateServices.Administration.UpdateTypes UpdateTypes {get;set;}
##Enumerate ApprovedStates
D:\> [Enum]::GetValues([Microsoft.UpdateServices.Administration.ApprovedStates])
LatestRevisionApproved
HasStaleUpdateApprovals
NotApproved
Declined
Any
# Assign Approved States to NotAppoved
D:\> $UpdateScope.ApprovedStates=[Microsoft.UpdateServices.Administration.ApprovedStates]'NotApproved'
## Now let's look at Installation States
D:\> [enum]::GetValues([Microsoft.UpdateServices.Administration.UpdateInstallationStates])
Unknown
NotApplicable
NotInstalled
Downloaded
Installed
Failed
InstalledPendingReboot
All
## Case: we want to find out about updates that are needed by the computer but not approved in WSUS
## In WSUS report for a machine we see Status and Approval columns. UpdateScope properties In WSUS API match thos:
## Status -> updateInstallationStates = 'NotInstalled'
## Approval -> ApprovedStates = 'NotApproved'
$updateScope = new-object Microsoft.UpdateServices.Administration.UpdateScope
$updateScope.ApprovedStates = [Microsoft.UpdateServices.Administration.ApprovedStates]'NotApproved'
$updateScope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]'NotInstalled'
$updateScope |fl
ApprovedStates : NotApproved
UpdateTypes : All
TextIncludes :
TextNotIncludes :
FromArrivalDate : 1/1/0001 12:00:00 AM
ToArrivalDate : 12/31/9999 11:59:59 PM
Categories : {}
Classifications : {}
IncludedInstallationStates : NotInstalled
ExcludedInstallationStates : 0
IsWsusInfrastructureUpdate : False
FromCreationDate : 1/1/0001 12:00:00 AM
ToCreationDate : 12/31/9999 11:59:59 PM
UpdateApprovalActions : All
ApprovedComputerTargetGroups : {}
UpdateSources : All
ExcludeOptionalUpdates : False
UpdateApprovalScope :
## Case: when computer DOWNLOADED an update and/or it has NOT INSTALLED an update
$UpdateScope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]'NotInstalled,Downloaded'
$UpdateScope | fl IncludedInstallationStates
IncludedInstallationStates : NotInstalled, Downloaded
## Final state of UpdateScope looks like this
D:\> $UpdateScope |fl
ApprovedStates : NotApproved
UpdateTypes : All
TextIncludes :
TextNotIncludes :
FromArrivalDate : 1/1/0001 12:00:00 AM
ToArrivalDate : 12/31/9999 11:59:59 PM
Categories : {}
Classifications : {}
IncludedInstallationStates : NotInstalled, Downloaded
ExcludedInstallationStates : 0
IsWsusInfrastructureUpdate : False
FromCreationDate : 1/1/0001 12:00:00 AM
ToCreationDate : 12/31/9999 11:59:59 PM
UpdateApprovalActions : All
ApprovedComputerTargetGroups : {}
UpdateSources : All
ExcludeOptionalUpdates : False
UpdateApprovalScope :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment