Skip to content

Script to add an exclusion to Windows Defender may be simplified #2930

Open
@fdcastel

Description

@fdcastel

This script to add an exclusion to Windows Defender seems overly complex

Already discussed here (DBeaver is built on Eclipse Platform).

Suggestion

Replace the current

$exclusions=@( `
 "C:\Program Files\DBeaver\dbeaver.exe"); `
 $existingExclusions=[Collections.Generic.HashSet[String]](Get-MpPreference).ExclusionProcess; `
 if($existingExclusions -eq $null) { $existingExclusions = New-Object Collections.Generic.HashSet[String] }; `
 $exclusionsToAdd=[Linq.Enumerable]::ToArray([Linq.Enumerable]::Where($exclusions,[Func[object,bool]]{param($ex)!$existingExclusions.Contains($ex)})); `
 if($exclusionsToAdd.Length -gt 0){ Add-MpPreference -ExclusionProcess $exclusionsToAdd }

With the simpler

Add-MpPreference -ExclusionProcess 'C:\Program Files\DBeaver\dbeaver.exe'

Rationale

I tested the simpler version and it seems that Add-MpPreference already does exactly the same work the current script does.

  • It will APPEND the item to the list, not to REPLACE it.
  • If the list doesn't exists, it will CREATE it.
  • Tested on Windows 11 / Windows Powershell 5.1.

Community

  • I understand suggesting an enhancement doesn't mandate anyone to implement it. Other contributors may consider this suggestion, or not, at their own convenience. The most efficient way to get it fixed is that I implement it myself and contribute it back as a good quality patch to the project.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions