mirror of
https://github.com/Raphire/Win11Debloat.git
synced 2026-11-26 07:26:18 +01:00
fix: skip features that the running Windows build does not support (#832)
This commit is contained in:
@@ -363,6 +363,21 @@ function Invoke-AllChanges {
|
|||||||
}
|
}
|
||||||
$undoIds = @($script:UndoParams.Keys)
|
$undoIds = @($script:UndoParams.Keys)
|
||||||
|
|
||||||
|
# Features passed as switches are not filtered by the GUI or the config import, so skip the ones this Windows build does not support
|
||||||
|
$currentBuild = Get-CurrentWindowsBuild
|
||||||
|
$unsupportedIds = @($applyIds | Where-Object { -not (Test-FeatureSupportedOnBuild -Feature $script:Features[$_] -Build $currentBuild) })
|
||||||
|
foreach ($id in $unsupportedIds) {
|
||||||
|
$feature = $script:Features[$id]
|
||||||
|
$range = @()
|
||||||
|
if ($feature.MinVersion) { $range += "build $($feature.MinVersion) or newer" }
|
||||||
|
if ($feature.MaxVersion) { $range += "build $($feature.MaxVersion) or older" }
|
||||||
|
Write-Warning "Skipping ${id}: it is only supported on Windows $($range -join ' and '), this system runs build $currentBuild."
|
||||||
|
|
||||||
|
# Also drop it from the parameters, so that later steps (such as the reboot advice) only see what was applied
|
||||||
|
[void]$script:Params.Remove($id)
|
||||||
|
}
|
||||||
|
$applyIds = @($applyIds | Where-Object { $unsupportedIds -notcontains $_ })
|
||||||
|
|
||||||
# ---- Determine if registry backup is needed ----
|
# ---- Determine if registry backup is needed ----
|
||||||
$needsBackup = $false
|
$needsBackup = $false
|
||||||
foreach ($id in $applyIds) {
|
foreach ($id in $applyIds) {
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ function Import-Settings {
|
|||||||
if (-not $feature) { continue }
|
if (-not $feature) { continue }
|
||||||
|
|
||||||
# Check version and feature compatibility using Features.json
|
# Check version and feature compatibility using Features.json
|
||||||
if (($feature.MinVersion -and $WinVersion -lt $feature.MinVersion) -or ($feature.MaxVersion -and $WinVersion -gt $feature.MaxVersion) -or ($feature.FeatureId -eq 'DisableModernStandbyNetworking' -and (-not $script:ModernStandbySupported))) {
|
if (-not (Test-FeatureSupportedOnBuild -Feature $feature -Build $WinVersion) -or ($feature.FeatureId -eq 'DisableModernStandbyNetworking' -and (-not $script:ModernStandbySupported))) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -418,7 +418,7 @@ function New-DynamicTweakControls {
|
|||||||
if ($feature.Category -ne $categoryName) { $featureIndex++; continue }
|
if ($feature.Category -ne $categoryName) { $featureIndex++; continue }
|
||||||
|
|
||||||
# Check version and feature compatibility using Features.json
|
# Check version and feature compatibility using Features.json
|
||||||
if (($feature.MinVersion -and $WinVersion -lt $feature.MinVersion) -or ($feature.MaxVersion -and $WinVersion -gt $feature.MaxVersion) -or ($feature.FeatureId -eq 'DisableModernStandbyNetworking' -and (-not $script:ModernStandbySupported))) {
|
if (-not (Test-FeatureSupportedOnBuild -Feature $feature -Build $WinVersion) -or ($feature.FeatureId -eq 'DisableModernStandbyNetworking' -and (-not $script:ModernStandbySupported))) {
|
||||||
$featureIndex++; continue
|
$featureIndex++; continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -451,7 +451,7 @@ function New-DynamicTweakControls {
|
|||||||
foreach ($fid in $_.FeatureIds) {
|
foreach ($fid in $_.FeatureIds) {
|
||||||
if ($featureMap.ContainsKey($fid)) {
|
if ($featureMap.ContainsKey($fid)) {
|
||||||
$f = $featureMap[$fid]
|
$f = $featureMap[$fid]
|
||||||
if (($f.MinVersion -and $WinVersion -lt $f.MinVersion) -or ($f.MaxVersion -and $WinVersion -gt $f.MaxVersion)) {
|
if (-not (Test-FeatureSupportedOnBuild -Feature $f -Build $WinVersion)) {
|
||||||
$allCompatible = $false
|
$allCompatible = $false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ function Import-ConfigToParams {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($feature.MinVersion -and $CurrentBuild -lt $feature.MinVersion) -or ($feature.MaxVersion -and $CurrentBuild -gt $feature.MaxVersion) -or ($feature.FeatureId -eq 'DisableModernStandbyNetworking' -and (-not $script:ModernStandbySupported))) {
|
if (-not (Test-FeatureSupportedOnBuild -Feature $feature -Build $CurrentBuild) -or ($feature.FeatureId -eq 'DisableModernStandbyNetworking' -and (-not $script:ModernStandbySupported))) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# Returns the build number of the running Windows version, or $null when it cannot be read.
|
||||||
|
function Get-CurrentWindowsBuild {
|
||||||
|
$build = 0
|
||||||
|
try {
|
||||||
|
# Get-ItemPropertyValue reports a missing value as a terminating error, which -ErrorAction SilentlyContinue does not suppress
|
||||||
|
$currentBuild = Get-ItemPropertyValue 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' CurrentBuild -ErrorAction Stop
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Verbose "Unable to read the Windows build number: $($_.Exception.Message)"
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
if ([int]::TryParse([string]$currentBuild, [ref]$build)) { return $build }
|
||||||
|
return $null
|
||||||
|
}
|
||||||
|
|
||||||
|
# Checks a feature's MinVersion / MaxVersion (Windows build numbers from Features.json) against a build number.
|
||||||
|
# A feature without limits, or a build that is not known, is treated as supported.
|
||||||
|
function Test-FeatureSupportedOnBuild {
|
||||||
|
param(
|
||||||
|
$Feature,
|
||||||
|
$Build
|
||||||
|
)
|
||||||
|
|
||||||
|
if ($null -eq $Feature -or $null -eq $Build) { return $true }
|
||||||
|
if ($Feature.MinVersion -and [int]$Build -lt [int]$Feature.MinVersion) { return $false }
|
||||||
|
if ($Feature.MaxVersion -and [int]$Build -gt [int]$Feature.MaxVersion) { return $false }
|
||||||
|
return $true
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ BeforeAll {
|
|||||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-JsonFile.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Add-Parameter.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Add-Parameter.ps1')
|
||||||
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Windows-BuildHelpers.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Import-ConfigToParams.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Import-ConfigToParams.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Test-ConfigConsistency.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Test-ConfigConsistency.ps1')
|
||||||
$script:ConfigFixturePath = Join-Path $PSScriptRoot 'TestData\JsonFileLoading\ExportedConfig.WithSettings.json'
|
$script:ConfigFixturePath = Join-Path $PSScriptRoot 'TestData\JsonFileLoading\ExportedConfig.WithSettings.json'
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ BeforeAll {
|
|||||||
function Set-StoreSearchSuggestionsDisabled { param($StoreAppsDatabase) $true }
|
function Set-StoreSearchSuggestionsDisabled { param($StoreAppsDatabase) $true }
|
||||||
|
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||||
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Windows-BuildHelpers.ps1')
|
||||||
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Get-RebootFeatureLabels.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\Features\Invoke-Changes.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\Features\Invoke-Changes.ps1')
|
||||||
|
|
||||||
# Builds a $script:Lang fixture whose Features section mirrors $script:Features exactly,
|
# Builds a $script:Lang fixture whose Features section mirrors $script:Features exactly,
|
||||||
@@ -425,6 +427,7 @@ Describe 'Invoke-AllChanges' {
|
|||||||
$script:CancelRequested = $false
|
$script:CancelRequested = $false
|
||||||
$script:ApplyProgressCallback = $null
|
$script:ApplyProgressCallback = $null
|
||||||
Mock Test-RunningAsSystem { $false }
|
Mock Test-RunningAsSystem { $false }
|
||||||
|
Mock Get-CurrentWindowsBuild { 26100 }
|
||||||
Mock Resolve-UndoRegFilePath { param($FileName) "Undo\$FileName" }
|
Mock Resolve-UndoRegFilePath { param($FileName) "Undo\$FileName" }
|
||||||
Mock New-RegistrySettingsBackup {}
|
Mock New-RegistrySettingsBackup {}
|
||||||
Mock Invoke-SystemRestorePoint { $true }
|
Mock Invoke-SystemRestorePoint { $true }
|
||||||
@@ -540,3 +543,119 @@ Describe 'Invoke-AllChanges' {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Describe 'Invoke-AllChanges build gate' {
|
||||||
|
BeforeEach {
|
||||||
|
$script:Params = @{ Modern = $true; Legacy = $true; Anyone = $true }
|
||||||
|
$script:UndoParams = @{ ModernUndo = $true }
|
||||||
|
$script:ControlParams = @('WhatIf', 'Silent', 'User', 'Sysprep')
|
||||||
|
$script:Features = @{
|
||||||
|
Modern = [PSCustomObject]@{ RegistryKey = 'modern.reg'; MinVersion = 22621; MaxVersion = $null }
|
||||||
|
Legacy = [PSCustomObject]@{ RegistryKey = 'legacy.reg'; MinVersion = $null; MaxVersion = 21999 }
|
||||||
|
Anyone = [PSCustomObject]@{ RegistryKey = 'anyone.reg' }
|
||||||
|
ModernUndo = [PSCustomObject]@{ RegistryUndoKey = 'undo.reg'; MinVersion = 22621; MaxVersion = $null }
|
||||||
|
}
|
||||||
|
$script:CancelRequested = $false
|
||||||
|
$script:ApplyProgressCallback = $null
|
||||||
|
$warnings = [System.Collections.Generic.List[string]]::new()
|
||||||
|
Mock Test-RunningAsSystem { $false }
|
||||||
|
Mock Resolve-UndoRegFilePath { param($FileName) "Undo\$FileName" }
|
||||||
|
Mock New-RegistrySettingsBackup {}
|
||||||
|
Mock Invoke-SystemRestorePoint { $true }
|
||||||
|
Mock Invoke-ApplyFeatures {}
|
||||||
|
Mock Invoke-UndoFeatures {}
|
||||||
|
Mock Write-Host {}
|
||||||
|
Mock Write-Warning { $warnings.Add([string]$Message) }
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'skips features that need a newer build and keeps the rest' {
|
||||||
|
Mock Get-CurrentWindowsBuild { 19045 }
|
||||||
|
|
||||||
|
Invoke-AllChanges
|
||||||
|
|
||||||
|
Should -Invoke Invoke-ApplyFeatures -Times 1 -Exactly -ParameterFilter {
|
||||||
|
@($FeatureIds).Count -eq 2 -and $FeatureIds -contains 'Legacy' -and $FeatureIds -contains 'Anyone'
|
||||||
|
}
|
||||||
|
$warnings | Should -HaveCount 1
|
||||||
|
$warnings[0] | Should -BeLike 'Skipping Modern: * build 22621 or newer*build 19045*'
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'skips features that are only supported on an older build' {
|
||||||
|
Mock Get-CurrentWindowsBuild { 26100 }
|
||||||
|
|
||||||
|
Invoke-AllChanges
|
||||||
|
|
||||||
|
Should -Invoke Invoke-ApplyFeatures -Times 1 -Exactly -ParameterFilter {
|
||||||
|
@($FeatureIds).Count -eq 2 -and $FeatureIds -contains 'Modern' -and $FeatureIds -contains 'Anyone'
|
||||||
|
}
|
||||||
|
$warnings | Should -HaveCount 1
|
||||||
|
$warnings[0] | Should -BeLike 'Skipping Legacy: * build 21999 or older*build 26100*'
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'does not back up the registry keys of skipped features' {
|
||||||
|
Mock Get-CurrentWindowsBuild { 19045 }
|
||||||
|
|
||||||
|
Invoke-AllChanges
|
||||||
|
|
||||||
|
Should -Invoke New-RegistrySettingsBackup -Times 1 -Exactly -ParameterFilter {
|
||||||
|
$ActionableKeys -notcontains 'Modern' -and $ActionableKeys -contains 'Legacy'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'does not apply anything gated when every selected feature is skipped' {
|
||||||
|
Mock Get-CurrentWindowsBuild { 19045 }
|
||||||
|
$script:Params = @{ Modern = $true }
|
||||||
|
$script:UndoParams = @{}
|
||||||
|
|
||||||
|
Invoke-AllChanges
|
||||||
|
|
||||||
|
Should -Invoke Invoke-ApplyFeatures -Times 0 -Exactly
|
||||||
|
Should -Invoke New-RegistrySettingsBackup -Times 0 -Exactly
|
||||||
|
$warnings | Should -HaveCount 1
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'applies every feature when the build cannot be read' {
|
||||||
|
Mock Get-CurrentWindowsBuild { $null }
|
||||||
|
|
||||||
|
Invoke-AllChanges
|
||||||
|
|
||||||
|
Should -Invoke Invoke-ApplyFeatures -Times 1 -Exactly -ParameterFilter { @($FeatureIds).Count -eq 3 }
|
||||||
|
$warnings | Should -HaveCount 0
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'drops skipped features from the parameters so that they are not part of the reboot advice' {
|
||||||
|
Mock Get-CurrentWindowsBuild { 19045 }
|
||||||
|
Mock Get-Translation { $Key }
|
||||||
|
$script:Features['Modern'] | Add-Member -NotePropertyName RequiresReboot -NotePropertyValue $true
|
||||||
|
$script:Features['Legacy'] | Add-Member -NotePropertyName RequiresReboot -NotePropertyValue $true
|
||||||
|
|
||||||
|
Invoke-AllChanges
|
||||||
|
|
||||||
|
$script:Params.ContainsKey('Modern') | Should -BeFalse
|
||||||
|
$script:Params.ContainsKey('Legacy') | Should -BeTrue
|
||||||
|
$labels = @(Get-RebootFeatureLabels)
|
||||||
|
$labels | Should -Contain 'Legacy'
|
||||||
|
$labels | Should -Not -Contain 'Modern'
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'does not write anything to the output when it skips a feature' {
|
||||||
|
Mock Get-CurrentWindowsBuild { 19045 }
|
||||||
|
# $PSBoundParameters is a generic dictionary whose Remove() returns a Boolean, unlike Hashtable.Remove()
|
||||||
|
$script:Params = [System.Collections.Generic.Dictionary[string, object]]::new()
|
||||||
|
$script:Params['Modern'] = $true
|
||||||
|
$script:Params['Anyone'] = $true
|
||||||
|
|
||||||
|
@(Invoke-AllChanges) | Should -HaveCount 0
|
||||||
|
$script:Params.ContainsKey('Modern') | Should -BeFalse
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'leaves undo selections alone' {
|
||||||
|
Mock Get-CurrentWindowsBuild { 19045 }
|
||||||
|
|
||||||
|
Invoke-AllChanges
|
||||||
|
|
||||||
|
Should -Invoke Invoke-UndoFeatures -Times 1 -Exactly -ParameterFilter {
|
||||||
|
@($FeatureIds).Count -eq 1 -and $FeatureIds[0] -eq 'ModernUndo'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ BeforeAll {
|
|||||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-AppSelection.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-AppSelection.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-Deployment.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-Deployment.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-Navigation.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-Navigation.ps1')
|
||||||
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Windows-BuildHelpers.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-TweaksBuilder.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\GUI\MainWindow-TweaksBuilder.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\GUI\Set-WindowThemeResources.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\GUI\Set-WindowThemeResources.ps1')
|
||||||
$script:LanguagesPath = Join-Path $PSScriptRoot '..\Config\Languages'
|
$script:LanguagesPath = Join-Path $PSScriptRoot '..\Config\Languages'
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ BeforeAll {
|
|||||||
foreach ($file in @('FileIO/Import-JsonFile', 'FileIO/Import-LanguageFile',
|
foreach ($file in @('FileIO/Import-JsonFile', 'FileIO/Import-LanguageFile',
|
||||||
'GUI/Ui-Preferences', 'GUI/Show-SettingsDialog', 'GUI/Set-WindowThemeResources',
|
'GUI/Ui-Preferences', 'GUI/Show-SettingsDialog', 'GUI/Set-WindowThemeResources',
|
||||||
'GUI/MainWindow-Localization', 'GUI/MainWindow-TweaksBuilder', 'GUI/MainWindow-AppSelection',
|
'GUI/MainWindow-Localization', 'GUI/MainWindow-TweaksBuilder', 'GUI/MainWindow-AppSelection',
|
||||||
'GUI/MainWindow-Deployment', 'GUI/Show-Bubble', 'Helpers/Get-UserName')) {
|
'GUI/MainWindow-Deployment', 'GUI/Show-Bubble', 'Helpers/Get-UserName', 'Helpers/Windows-BuildHelpers')) {
|
||||||
. "$script:RepoRoot/Scripts/$file.ps1"
|
. "$script:RepoRoot/Scripts/$file.ps1"
|
||||||
}
|
}
|
||||||
$script:LanguagesPath = Join-Path $script:RepoRoot 'Config/Languages'
|
$script:LanguagesPath = Join-Path $script:RepoRoot 'Config/Languages'
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ BeforeAll {
|
|||||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Registry-PathHelpers.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Registry-PathHelpers.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Get-RegFileOperations.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Get-RegFileOperations.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\User-HiveHelpers.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\User-HiveHelpers.ps1')
|
||||||
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Windows-BuildHelpers.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\Features\Invoke-Changes.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\Features\Invoke-Changes.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\Features\Backup-RegistryFeatureSelection.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\Features\Backup-RegistryFeatureSelection.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Save-ToFile.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Save-ToFile.ps1')
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ BeforeAll {
|
|||||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-LanguageFile.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Add-Parameter.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Add-Parameter.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Save-ToFile.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Save-ToFile.ps1')
|
||||||
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Windows-BuildHelpers.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-Settings.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-Settings.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Save-Settings.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Save-Settings.ps1')
|
||||||
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-AppsFromFile.ps1')
|
. (Join-Path $PSScriptRoot '..\Scripts\FileIO\Import-AppsFromFile.ps1')
|
||||||
|
|||||||
@@ -0,0 +1,68 @@
|
|||||||
|
BeforeAll {
|
||||||
|
. (Join-Path $PSScriptRoot '..\Scripts\Helpers\Windows-BuildHelpers.ps1')
|
||||||
|
}
|
||||||
|
|
||||||
|
Describe 'Get-CurrentWindowsBuild' {
|
||||||
|
It 'returns the build number as a number' {
|
||||||
|
Mock Get-ItemPropertyValue { '26100' }
|
||||||
|
|
||||||
|
Get-CurrentWindowsBuild | Should -Be 26100
|
||||||
|
Get-CurrentWindowsBuild | Should -BeOfType [int]
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'returns nothing when the value is not a number' {
|
||||||
|
Mock Get-ItemPropertyValue { 'unknown' }
|
||||||
|
|
||||||
|
Get-CurrentWindowsBuild | Should -BeNullOrEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'returns nothing instead of failing when reading the registry throws' {
|
||||||
|
Mock Get-ItemPropertyValue { throw 'Property CurrentBuild does not exist' }
|
||||||
|
|
||||||
|
{ Get-CurrentWindowsBuild } | Should -Not -Throw
|
||||||
|
Get-CurrentWindowsBuild | Should -BeNullOrEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'asks for a terminating error so that a missing value is caught' {
|
||||||
|
Mock Get-ItemPropertyValue { '19045' }
|
||||||
|
|
||||||
|
Get-CurrentWindowsBuild | Out-Null
|
||||||
|
|
||||||
|
Should -Invoke Get-ItemPropertyValue -Times 1 -Exactly -ParameterFilter { $ErrorAction -eq 'Stop' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Describe 'Test-FeatureSupportedOnBuild' {
|
||||||
|
It 'returns <Expected> for MinVersion <Min>, MaxVersion <Max> on build <Build>' -ForEach @(
|
||||||
|
@{ Min = 22621; Max = $null; Build = 19045; Expected = $false }
|
||||||
|
@{ Min = 22621; Max = $null; Build = 22620; Expected = $false }
|
||||||
|
@{ Min = 22621; Max = $null; Build = 22621; Expected = $true }
|
||||||
|
@{ Min = 22621; Max = $null; Build = 26100; Expected = $true }
|
||||||
|
@{ Min = $null; Max = 21999; Build = 19045; Expected = $true }
|
||||||
|
@{ Min = $null; Max = 21999; Build = 21999; Expected = $true }
|
||||||
|
@{ Min = $null; Max = 21999; Build = 22000; Expected = $false }
|
||||||
|
@{ Min = 22000; Max = 22631; Build = 22631; Expected = $true }
|
||||||
|
@{ Min = 22000; Max = 22631; Build = 26100; Expected = $false }
|
||||||
|
@{ Min = $null; Max = $null; Build = 10240; Expected = $true }
|
||||||
|
) {
|
||||||
|
$feature = [PSCustomObject]@{ MinVersion = $Min; MaxVersion = $Max }
|
||||||
|
|
||||||
|
Test-FeatureSupportedOnBuild -Feature $feature -Build $Build | Should -Be $Expected
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'does not limit a feature when the build is not known' {
|
||||||
|
$feature = [PSCustomObject]@{ MinVersion = 22621; MaxVersion = $null }
|
||||||
|
|
||||||
|
Test-FeatureSupportedOnBuild -Feature $feature -Build $null | Should -BeTrue
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'does not limit an unknown feature' {
|
||||||
|
Test-FeatureSupportedOnBuild -Feature $null -Build 19045 | Should -BeTrue
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'compares build numbers as numbers when the build is a string' {
|
||||||
|
$feature = [PSCustomObject]@{ MinVersion = 22621; MaxVersion = $null }
|
||||||
|
|
||||||
|
Test-FeatureSupportedOnBuild -Feature $feature -Build '9600' | Should -BeFalse
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -437,6 +437,7 @@ if (-not $script:WingetInstalled -and -not $Silent) {
|
|||||||
. "$PSScriptRoot/Scripts/Helpers/Get-FriendlyRegistryBackupTarget.ps1"
|
. "$PSScriptRoot/Scripts/Helpers/Get-FriendlyRegistryBackupTarget.ps1"
|
||||||
. "$PSScriptRoot/Scripts/Helpers/Get-FriendlyTargetUserName.ps1"
|
. "$PSScriptRoot/Scripts/Helpers/Get-FriendlyTargetUserName.ps1"
|
||||||
. "$PSScriptRoot/Scripts/Helpers/Get-RebootFeatureLabels.ps1"
|
. "$PSScriptRoot/Scripts/Helpers/Get-RebootFeatureLabels.ps1"
|
||||||
|
. "$PSScriptRoot/Scripts/Helpers/Windows-BuildHelpers.ps1"
|
||||||
. "$PSScriptRoot/Scripts/Helpers/Import-ConfigToParams.ps1"
|
. "$PSScriptRoot/Scripts/Helpers/Import-ConfigToParams.ps1"
|
||||||
. "$PSScriptRoot/Scripts/Helpers/Test-ConfigConsistency.ps1"
|
. "$PSScriptRoot/Scripts/Helpers/Test-ConfigConsistency.ps1"
|
||||||
. "$PSScriptRoot/Scripts/Helpers/Get-TargetUserForAppRemoval.ps1"
|
. "$PSScriptRoot/Scripts/Helpers/Get-TargetUserForAppRemoval.ps1"
|
||||||
|
|||||||
Reference in New Issue
Block a user