diff --git a/private/Start-DscUpdate.ps1 b/private/Start-DscUpdate.ps1 index 367e3b7..8907af9 100644 --- a/private/Start-DscUpdate.ps1 +++ b/private/Start-DscUpdate.ps1 @@ -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 @@ -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") diff --git a/public/Get-KbInstalledUpdate.ps1 b/public/Get-KbInstalledUpdate.ps1 index 7bc8390..f049d13 100644 --- a/public/Get-KbInstalledUpdate.ps1 +++ b/public/Get-KbInstalledUpdate.ps1 @@ -73,6 +73,14 @@ 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 { @@ -80,6 +88,13 @@ function Get-KbInstalledUpdate { $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 :( diff --git a/public/Get-KbUpdate.ps1 b/public/Get-KbUpdate.ps1 index 1b94f8a..369e635 100644 --- a/public/Get-KbUpdate.ps1 +++ b/public/Get-KbUpdate.ps1 @@ -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 { diff --git a/public/Select-KbLatest.ps1 b/public/Select-KbLatest.ps1 index 0037080..6d2dbf1 100644 --- a/public/Select-KbLatest.ps1 +++ b/public/Select-KbLatest.ps1 @@ -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 } } \ No newline at end of file diff --git a/tests/Integration.Tests.ps1 b/tests/Integration.Tests.ps1 index 5f7ddcf..105f245 100644 --- a/tests/Integration.Tests.ps1 +++ b/tests/Integration.Tests.ps1 @@ -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" {