diff --git a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WindowsDefenderConfigurator.java b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WindowsDefenderConfigurator.java index bc105459999..b22a1dc88ef 100644 --- a/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WindowsDefenderConfigurator.java +++ b/bundles/org.eclipse.ui.workbench/eclipseui/org/eclipse/ui/internal/WindowsDefenderConfigurator.java @@ -342,14 +342,12 @@ public static String createAddExclusionsPowershellCommand(String extraSeparator) // // For .NET's stream API called LINQ see: // https://learn.microsoft.com/en-us/dotnet/api/system.linq.enumerable - String excludedPaths = paths.stream().map(Path::toString).map(p -> '"' + p + '"') - .collect(Collectors.joining(',' + extraSeparator)); - final String exclusionType = "ExclusionProcess"; //$NON-NLS-1$ - return String.join(';' + extraSeparator, "$exclusions=@(" + extraSeparator + excludedPaths + ')', //$NON-NLS-1$ - "$existingExclusions=[Collections.Generic.HashSet[String]](Get-MpPreference)." + exclusionType, //$NON-NLS-1$ - "if($existingExclusions -eq $null) { $existingExclusions = New-Object Collections.Generic.HashSet[String] }", //$NON-NLS-1$ - "$exclusionsToAdd=[Linq.Enumerable]::ToArray([Linq.Enumerable]::Where($exclusions,[Func[object,bool]]{param($ex)!$existingExclusions.Contains($ex)}))", //$NON-NLS-1$ - "if($exclusionsToAdd.Length -gt 0){ Add-MpPreference -" + exclusionType + " $exclusionsToAdd }"); //$NON-NLS-1$ //$NON-NLS-2$ + String excludedPaths = paths.stream().map(Path::toString).map(p -> "'" + p.replace("'", "''") + "'") + .collect(Collectors.joining(',')); + return String.join(";", + "$pathsToExclude = @(" + excludedPaths + ")", + "Add-MpPreference -ExclusionProcess $pathsToExclude" + ); } private static void excludeDirectoryFromScanning(IProgressMonitor monitor) throws IOException {