New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(MODULES-7222) Create a task to list the Update History #83
Conversation
This commit adds a script that will query the update history of a Windows computer and then output that information for a bolt or PE 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.
Note that I would like to keep the three commits separate as I intend to write a blog post showing the progression of this script. |
tasks/update_history.ps1
Outdated
'UninstallationSteps' = @() | ||
'UninstallationNotes' = Get-SafeString $_.UninstallationNotes | ||
'SupportUrl' = Get-SafeString $_.SupportUrl | ||
'Categories' = @() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly better to set Categories
equal to New-Object System.Collections.ArrayList
and then on line 75 you could use $props.Categories.Add($_.Name)
.
I think that should be slightly more performant but I'm not sure how much it matters in this context.
Edit: I just realized I don't understand why this is being initialized and then added to on L75 instead of directly set here - I'm definitely missing something I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Categories is an enumerable COM object type. By setting Categories
to an array and then appending items to it, I can keep the type as String[]
. If I used a pipeline I will end up with String
for single categories and null
for empty categories.
tasks/update_history.ps1
Outdated
$_.Categories | % { $props.Categories += $_.Name } | Out-Null | ||
$props['UpdateIdentity']['RevisionNumber'] = $_.UpdateIdentity.RevisionNumber | ||
$props['UpdateIdentity']['UpdateID'] = $_.UpdateIdentity.UpdateID | ||
$_.UninstallationSteps | % { $props.UninstallationSteps += $_ } | Out-Null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'm missing some context - why not just assign this directly on line 69?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above in Categories
tasks/update_history.ps1
Outdated
$Searcher.QueryHistory(0, $historyCount) | ForEach-Object -Process { | ||
if ($historyCount -gt $MaximumUpdates) { $historyCount = $MaximumUpdates } | ||
$Searcher.QueryHistory(0, $historyCount) | | ||
Where-Object { ($Title -eq '') -or ($_.Title -match $Title) } | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For these two lines do we want to use [string]::IsNullOrEmpty($Variable)
instead of $Variable -eq ''
? Then I think we don't have to set an initial value in the param block.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
This commit modifies the update_history task to accept three new parameters which will filter what updates are returned in the history * Title - Regular expression match against update title * UpdateID - String comparions of the unique UpdateID * MaximumUpdates - Limit the number of history items returned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking on this a bit more over my initial coffee... Should this pattern include pester tests for the script?
I don't think tasks/bolt has a super established pattern on this and we may want it left out of the blog (or, possibly, just mentioned and pointed to rather than walked through), but it feels like good practice.
This PR adds a script that will query the update history of a Windows
computer and then output that information for a bolt or PE Task.