Skip to content
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

Merged
merged 3 commits into from Jun 1, 2018

Conversation

glennsarti
Copy link
Contributor

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.

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.
@glennsarti
Copy link
Contributor Author

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.

'UninstallationSteps' = @()
'UninstallationNotes' = Get-SafeString $_.UninstallationNotes
'SupportUrl' = Get-SafeString $_.SupportUrl
'Categories' = @()
Copy link
Contributor

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.

Copy link
Contributor Author

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.

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

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?

Copy link
Contributor Author

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

$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) } |
Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

@michaeltlombardi michaeltlombardi left a 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.

@michaeltlombardi michaeltlombardi merged commit 8baf74c into puppetlabs:master Jun 1, 2018
@michaeltlombardi
Copy link
Contributor

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants