Skip to content

Commit

Permalink
Additional features and bug fixes (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
potatoqualitee authored Sep 19, 2022
1 parent 8da5161 commit 817b949
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
15 changes: 12 additions & 3 deletions private/Start-DscUpdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ function Start-DscUpdate {

# load up if a job
if (-not (Get-Module kbupdate)) {
$null = Import-Module PSSQLite -RequiredVersion 1.1.0 4>$null
$null = Import-Module PSFramework -RequiredVersion 1.7.227 4>$null
$null = Import-Module PSSQLite 4>$null
$null = Import-Module PSFramework 4>$null
$null = Import-Module kbupdate 4>$null

if ($PSVersionTable.PSVersion.Major -gt 5) {
$null = Import-Module -UseWindowsPowerShell PSDesiredStateConfiguration -MaximumVersion 1.1 *>$null
}
}

# No idea why this sometimes happens
Expand Down Expand Up @@ -452,7 +456,12 @@ function Start-DscUpdate {
$VerbosePreference,
$ManualFileName
)
Import-Module PSDesiredStateConfiguration 4>$null

if ($PSVersionTable.PSVersion.Major -gt 5) {
Import-Module -UseWindowsPowerShell PSDesiredStateConfiguration -MaximumVersion 1.1 *>$null
} else {
Import-Module PSDesiredStateConfiguration 4>$null
}
Import-Module xPSDesiredStateConfiguration -RequiredVersion 9.2.0 4>$null
Import-Module xWindowsUpdate -RequiredVersion 3.0.0 4>$null
$PSDefaultParameterValues.Remove("Invoke-WebRequest:ErrorAction")
Expand Down
15 changes: 15 additions & 0 deletions public/Get-KbInstalledUpdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,28 @@ function Get-KbInstalledUpdate {
foreach ($name in $pattern) {
$packages += Get-Package -IncludeWindowsInstaller -ProviderName msi, msu, Programs -Name "*$name*" -ErrorAction SilentlyContinue
$packages += Get-Package -ProviderName msi, msu, Programs -Name "*$name*" -ErrorAction SilentlyContinue
if ((Get-Service wuauserv | Where-Object StartType -ne Disabled)) {
$session = [type]::GetTypeFromProgID("Microsoft.Update.Session")
$wua = [activator]::CreateInstance($session)
$updatesearcher = $wua.CreateUpdateSearcher()
$count = $updatesearcher.GetTotalHistoryCount()
$packages += $updatesearcher.QueryHistory(0, $count) | Where-Object Name -match $Pattern
}

}
$packages = $packages | Sort-Object -Unique Name
} else {
$packages = @()
$packages += Get-Package -IncludeWindowsInstaller -ProviderName msi, msu, Programs
$packages += Get-Package -ProviderName msi, msu, Programs
$packages = $packages | Sort-Object -Unique Name
if ((Get-Service wuauserv | Where-Object StartType -ne Disabled)) {
$session = [type]::GetTypeFromProgID("Microsoft.Update.Session")
$wua = [activator]::CreateInstance($session)
$updatesearcher = $wua.CreateUpdateSearcher()
$count = $updatesearcher.GetTotalHistoryCount()
$packages += $updatesearcher.QueryHistory(0, $count)
}
}
# Cim never reports stuff in a package :(

Expand Down
4 changes: 3 additions & 1 deletion public/Get-KbUpdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ function Get-KbUpdate {
}

Write-PSFMessage -Level Verbose -Message "Source set to $Source"
Write-PSFMessage -Level Verbose -Message "Operating system set to $OperatingSystem"
if ($OperatingSystem) {
Write-PSFMessage -Level Verbose -Message "Operating system set to $OperatingSystem"
}

$script:allresults = @()
function Get-KbItemFromDb {
Expand Down
6 changes: 3 additions & 3 deletions public/Select-KbLatest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ function Select-KbLatest {
$allkbs += $InputObject
}
end {
$matches = @()
$match = @()
foreach ($kb in $allkbs) {
$otherkbs = $allkbs | Where-Object Id -ne $kb.Id
$matches += $allkbs | Where-Object { $PSItem.Id -eq $kb.Id -and $otherkbs.Supersedes.Kb -notcontains $kb.Id }
$match += $allkbs | Where-Object { $PSItem.Id -eq $kb.Id -and $otherkbs.Supersedes.Kb -notcontains $kb.Id }
}
$matches | Sort-Object UpdateId -Unique
$match | Sort-Object -Property @{Expression = "Id"; Descending = $true }, @{Expression = "LastModified"; Descending = $true } -Unique
}
}
2 changes: 1 addition & 1 deletion tests/Integration.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Describe "Integration Tests" -Tag "IntegrationTests" {
$results = Get-KbUpdate -Pattern 979906
$results.Count | Should -Be 3
$results = Get-KbUpdate -Pattern 2416447, 979906 -Latest
$results.Count | Should -Be 3
$results.Count | Should -Be 2
}

It -Skip "does not overwrite links" {
Expand Down

0 comments on commit 817b949

Please sign in to comment.