Skip to content

Commit

Permalink
New parameter UpdateNameFilter +semver: minor
Browse files Browse the repository at this point in the history
  • Loading branch information
codaamok committed Sep 23, 2022
1 parent 298664f commit 7bcb427
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- New parameter `-UpdateNameFilter` for `Invoke-CMSnowflakePatching`

## [0.3.0] - 2022-09-23
### Added
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,4 @@ By default it doesn't reboot or make any retry attempts, but there parameters fo
## To do

- Pass alternate credentials for connecting to remote hosts
- Pass a filter of update name, article IDs, or update IDs, to `Invoke-CMSnowflakePatching` to specify which updates to install
- Consider using PendingReboot or Test-PendingReboot from the gallery to make the `IsPendingReboot` reflect more than just the newly installed updates exit code
29 changes: 24 additions & 5 deletions docs/Invoke-CMSnowflakePatching.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,24 @@ Invoke software update installation for a ConfigMgr client, an array of clients,

### ByChoosingConfigMgrCollection (Default)
```
Invoke-CMSnowflakePatching [-ChooseCollection] [-AllowReboot] [-Attempts <Int32>] [-RebootTimeoutMins <Int32>]
[-InstallUpdatesTimeoutMins <Int32>] [-SoftwareUpdateScanCycleTimeoutMins <Int32>]
[-InvokeSoftwareUpdateInstallTimeoutMins <Int32>] [<CommonParameters>]
Invoke-CMSnowflakePatching [-ChooseCollection] [-AllowReboot] [-Attempts <Int32>]
[-UpdateNameFilter <String[]>] [-RebootTimeoutMins <Int32>] [-InstallUpdatesTimeoutMins <Int32>]
[-SoftwareUpdateScanCycleTimeoutMins <Int32>] [-InvokeSoftwareUpdateInstallTimeoutMins <Int32>]
[<CommonParameters>]
```

### ByComputerName
```
Invoke-CMSnowflakePatching -ComputerName <String[]> [-AllowReboot] [-Attempts <Int32>]
[-RebootTimeoutMins <Int32>] [-InstallUpdatesTimeoutMins <Int32>]
[-UpdateNameFilter <String[]>] [-RebootTimeoutMins <Int32>] [-InstallUpdatesTimeoutMins <Int32>]
[-SoftwareUpdateScanCycleTimeoutMins <Int32>] [-InvokeSoftwareUpdateInstallTimeoutMins <Int32>]
[<CommonParameters>]
```

### ByConfigMgrCollectionId
```
Invoke-CMSnowflakePatching -CollectionId <String> [-AllowReboot] [-Attempts <Int32>]
[-RebootTimeoutMins <Int32>] [-InstallUpdatesTimeoutMins <Int32>]
[-UpdateNameFilter <String[]>] [-RebootTimeoutMins <Int32>] [-InstallUpdatesTimeoutMins <Int32>]
[-SoftwareUpdateScanCycleTimeoutMins <Int32>] [-InvokeSoftwareUpdateInstallTimeoutMins <Int32>]
[<CommonParameters>]
```
Expand Down Expand Up @@ -192,6 +193,24 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -UpdateNameFilter
One or more strings used to filter the updates you want to invoke the installation of based on name.
It is advised to either provide full or partial strings of the match you need.
The function wraps wildcards around the filter.
For example, if you provide '7-Zip', the function will search for available updates with '%7-Zip%'.
```yaml
Type: String[]
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
### -RebootTimeoutMins
How long to wait for a host to become responsive again after reboot.
This parameter is hidden from tab completion.
Expand Down
31 changes: 29 additions & 2 deletions src/Public/Invoke-CMSnowflakePatching.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ function Invoke-CMSnowflakePatching {
Specify the number of retries you would like to script to make when a software update install failure is detected.
In other words, if software updates fail to install, and you specify 2 for the Attempts parameter, the script will
attempts installation twice. The default value is 1.
.PARAMETER UpdateNameFilter
One or more strings used to filter the updates you want to invoke the installation of based on name.
It is advised to either provide full or partial strings of the match you need. The function wraps wildcards around the filter.
For example, if you provide '7-Zip', the function will search for available updates with '%7-Zip%'.
.PARAMETER RebootTimeoutMins
How long to wait for a host to become responsive again after reboot.
This parameter is hidden from tab completion.
Expand Down Expand Up @@ -115,6 +119,17 @@ function Invoke-CMSnowflakePatching {
})]
[Int]$Attempts = 1,

[Parameter()]
[ValidateScript({
if ($_ -match '%') {
throw 'String can not contain character %'
}
else {
$true
}
})]
[String[]]$UpdateNameFilter,

[Parameter(DontShow)]
[Int]$RebootTimeoutMins = 120,

Expand Down Expand Up @@ -250,7 +265,8 @@ function Invoke-CMSnowflakePatching {
ArgumentList = @(
$Member.Name,
$AllowReboot.IsPresent,
$Attempts,
$Attempts,
(,$UpdateNameFilter),
$InvokeSoftwareUpdateInstallTimeoutMins,
$InstallUpdatesTimeoutMins,
$RebootTimeoutMins
Expand All @@ -261,16 +277,27 @@ function Invoke-CMSnowflakePatching {
[String]$ComputerName,
[Bool]$AllowReboot,
[Int]$Attempts,
[String[]]$UpdateNameFilter,
[Int]$InvokeSoftwareUpdateInstallTimeoutMins,
[Int]$InstallUpdatesTimeoutMins,
[Int]$RebootTimeoutMins
)

$Module = Get-Module 'PSCMSnowflakePatching'



if (-not [String]::IsNullOrWhiteSpace($UpdateNameFilter)) {
$Filter = 'ComplianceState = 0 AND (EvaluationState = 0 OR EvaluationState = 1 OR EvaluationState = 13) AND (Name LIKE "%{0}%")' -f
[String]::Join('%" OR Name LIKE "%', $UpdateNameFilter)
}
else {
$Filter = 'ComplianceState = 0 AND (EvaluationState = 0 OR EvaluationState = 1 OR EvaluationState = 13)'
}

$GetCMSoftwareUpdatesSplat = @{
ComputerName = $ComputerName
Filter = 'ComplianceState = 0 AND (EvaluationState = 0 OR EvaluationState = 1 OR EvaluationState = 13)'
Filter = $Filter
ErrorAction = 'Stop'
}
[CimInstance[]]$UpdatesToInstall = Get-CMSoftwareUpdates @GetCMSoftwareUpdatesSplat
Expand Down

0 comments on commit 7bcb427

Please sign in to comment.