Skip to content
Permalink
Browse files

(MODULES-7222) Add detailed parameter to update_history task

Previously the update_history task would return verbose information. This commit
adds a task parameter called Detailed which outputs this verbose information
when asked for, and by default returns a smaller subset of data.
  • Loading branch information...
glennsarti committed May 30, 2018
1 parent 4bcc461 commit f2ade674807c8079d97158adacda599f0d67b345
Showing with 31 additions and 10 deletions.
  1. +10 −0 tasks/update_history.json
  2. +21 −10 tasks/update_history.ps1
@@ -0,0 +1,10 @@
{
"description": "Returns a history of installed Windows Updates.",
"parameters": {
"detailed": {
"description": "Return detailed update information. Default is to return basic information",
"type": "Optional[Boolean]"
}
},
"input_method": "powershell"
}
@@ -1,3 +1,9 @@
[CmdletBinding()]
Param(
[Parameter(Mandatory = $False)]
[Switch]$Detailed
)

Function Get-SafeString($value) {
if ($value -eq $null) {
Write-Output ''
@@ -54,28 +60,33 @@ $Searcher = $Session.CreateUpdateSearcher()
$historyCount = $Searcher.GetTotalHistoryCount()
$Searcher.QueryHistory(0, $historyCount) | ForEach-Object -Process {
# Returns IUpdateHistoryEntry https://msdn.microsoft.com/en-us/library/windows/desktop/aa386400(v=vs.85).aspx

# Basic Settings
$props = @{
'Operation' = Convert-ToUpdateOperationString $_.Operation
'ResultCode' = Convert-ToOperationResultCodeString $_.ResultCode
'HResult' = $_.HResult
'Date' = Get-SafeDateTime $_.Date
'UpdateIdentity' = @{}
'Title' = Get-SafeString $_.Title
'Description' = Get-SafeString $_.Description
'UnmappedResultCode' = $_.UnmappedResultCode
'ClientApplicationID' = Get-SafeString $_.ClientApplicationID
'ServerSelection' = Convert-ToServerSelectionString $_.ServerSelection
'ServiceID' = Get-SafeString $_.ServiceID
'UninstallationSteps' = @()
'UninstallationNotes' = Get-SafeString $_.UninstallationNotes
'SupportUrl' = Get-SafeString $_.SupportUrl
'Categories' = @()
}

$_.Categories | % { $props.Categories += $_.Name } | Out-Null
$props['UpdateIdentity']['RevisionNumber'] = $_.UpdateIdentity.RevisionNumber
$props['UpdateIdentity']['UpdateID'] = $_.UpdateIdentity.UpdateID
$_.UninstallationSteps | % { $props.UninstallationSteps += $_ } | Out-Null

# Detailed Settings
if ($Detailed) {
$props['HResult'] = $_.HResult
$props['Description'] = Get-SafeString $_.Description
$props['UnmappedResultCode'] = $_.UnmappedResultCode
$props['ClientApplicationID'] = Get-SafeString $_.ClientApplicationID
$props['ServerSelection'] = Convert-ToServerSelectionString $_.ServerSelection
$props['UninstallationSteps'] = @()
$props['UninstallationNotes'] = Get-SafeString $_.UninstallationNotes
$props['SupportUrl'] = Get-SafeString $_.SupportUrl
$_.UninstallationSteps | % { $props.UninstallationSteps += $_ } | Out-Null
}

New-Object -TypeName PSObject -Property $props
} | ConvertTo-JSON

0 comments on commit f2ade67

Please sign in to comment.
You can’t perform that action at this time.