Skip to content

Commit

Permalink
(MODULES-7222) Add detailed parameter to update_history task
Browse files Browse the repository at this point in the history
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 f2ade67
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
10 changes: 10 additions & 0 deletions tasks/update_history.json
@@ -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"
}
31 changes: 21 additions & 10 deletions tasks/update_history.ps1
@@ -1,3 +1,9 @@
[CmdletBinding()]
Param(
[Parameter(Mandatory = $False)]
[Switch]$Detailed
)

Function Get-SafeString($value) {
if ($value -eq $null) {
Write-Output ''
Expand Down Expand Up @@ -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.