From a49624747fa6faed394f4b733b59c93d175eb514 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Fri, 24 Nov 2023 11:10:16 +0100 Subject: [PATCH] [platform] making the Defender configuration script resilient to missing excluded directories (IDEA-333056) GitOrigin-RevId: e1d3c4813f65c88f08357bf6d0c0e1df7e502336 --- bin/win/defender-exclusions.ps1 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/bin/win/defender-exclusions.ps1 b/bin/win/defender-exclusions.ps1 index db635725bea8..f074cfa76148 100644 --- a/bin/win/defender-exclusions.ps1 +++ b/bin/win/defender-exclusions.ps1 @@ -18,14 +18,16 @@ try { # returns `$true` when a path is already covered by the exclusion list function Test-Excluded ([string] $path, [string[]] $exclusions) { foreach ($exclusion in $exclusions) { - $expanded = [System.Environment]::ExpandEnvironmentVariables($exclusion) - $resolvedPaths = Resolve-Path -Path $expanded - foreach ($resolved in $resolvedPaths) { - $resolvedStr = $resolved.ProviderPath.ToString() - if ([cultureinfo]::InvariantCulture.CompareInfo.IsPrefix($path, $resolvedStr, @("IgnoreCase"))) { - return $true + try { + $expanded = [System.Environment]::ExpandEnvironmentVariables($exclusion) + $resolvedPaths = Resolve-Path -Path $expanded -ErrorAction Stop + foreach ($resolved in $resolvedPaths) { + $resolvedStr = $resolved.ProviderPath.ToString() + if ([cultureinfo]::InvariantCulture.CompareInfo.IsPrefix($path, $resolvedStr, @("IgnoreCase"))) { + return $true + } } - } + } catch [System.Management.Automation.ItemNotFoundException] { } } return $false