From d6bc33ec865d50efc6b8d4ccc2f789edd874fcee Mon Sep 17 00:00:00 2001 From: undergroundwires Date: Wed, 23 Feb 2022 06:52:46 +0100 Subject: [PATCH] Fix Windows 11 being detected as Windows 10 The logic was expecting major version in Windows 11 to be 11. However, in Windows 11, major version is not changed and it is till 10. This commit corrects logic to check build number that's guaranteed to be higher in Windows 11. --- src/application/collections/windows.yaml | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/application/collections/windows.yaml b/src/application/collections/windows.yaml index 444270b8..23a569ae 100644 --- a/src/application/collections/windows.yaml +++ b/src/application/collections/windows.yaml @@ -6875,15 +6875,18 @@ functions: # - `setDefaultOnWindows11` parameter changes this behavior to set the default value using `Set-MpPreference` # On Windows 10: # - If `default` argument is is provided, it's set using `Set-MpPreference` - # - `default` argument should not be provided if `Remove-MpPreference` is suppored in Windows 10, + # - `default` argument should not be provided if `Remove-MpPreference` is supported in Windows 10. revertCode: |- $propertyName = '{{ $property }}' {{ with $default }} $defaultValue = {{ . }} {{ end }} $setDefaultOnWindows10 = {{ with $default }} $true # {{ end }} $false $setDefaultOnWindows11 = {{ with $setDefaultOnWindows11 }} $true # {{ end }} $false + + $osVersion = [System.Environment]::OSVersion.Version + function Test-IsWindows10 { ($osVersion.Major -eq 10) -and ($osVersion.Build -lt 22000) } + function Test-IsWindows11 { ($osVersion.Major -gt 10) -or (($osVersion.Major -eq 10) -and ($osVersion.Build -ge 22000)) } # ------ Set-MpPreference ------ - if(($setDefaultOnWindows10 -and [System.Environment]::OSVersion.Version.Major -lt 11) ` - -or ($setDefaultOnWindows11 -and [System.Environment]::OSVersion.Version.Major -eq 11)) { + if(($setDefaultOnWindows10 -and (Test-IsWindows10)) -or ($setDefaultOnWindows11 -and (Test-IsWindows11))) { if((Get-MpPreference -ErrorAction Ignore).$propertyName -eq $defaultValue) { Write-Host "Skipping. `"$propertyName`" is already configured as desired `"$defaultValue`"." exit 0 @@ -7043,13 +7046,15 @@ functions: parameters: code: |- $warningMessage = '{{ $message }}' - $ignoredMajorVersions = @( - {{ with $ignoreWindows10 }}10{{ end }} - {{ with $ignoreWindows11 }}11{{ end }} - ) - $windowsVersion = [System.Environment]::OSVersion.Version.Major - if ($ignoredMajorVersions -contains $windowsVersion) { + $ignoreWindows10 = {{ with $ignoreWindows10 }} $true # {{ end }} $false + $ignoreWindows11 = {{ with $ignoreWindows11 }} $true # {{ end }} $false + + $osVersion = [System.Environment]::OSVersion.Version + function Test-IsWindows10 { ($osVersion.Major -eq 10) -and ($osVersion.Build -lt 22000) } + function Test-IsWindows11 { ($osVersion.Major -gt 10) -or (($osVersion.Major -eq 10) -and ($osVersion.Build -ge 22000)) } + + if (($ignoreWindows10 -and (Test-IsWindows10)) -or ($ignoreWindows11 -and (Test-IsWindows11))) { exit 0 # Skip }