Skip to content

Optimize Windows Defender exclusion script with native PowerShell #2930 #2939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

IamLRBA
Copy link

@IamLRBA IamLRBA commented Apr 24, 2025

cc
@HannesWell
Hello,
Since the script as per @fdcastel, to add an exclusion to Windows Defender seems overly complex. Based on your concerns about the proposed Add-MpPreference -ExclusionProcess 'C:\Program Files\DBeaver\dbeaver.exe' script, this script replaces the original complex LINQ-based exclusion check with a more idiomatic and simpler version PowerShell implementation.

How It Addresses the your Concerns:

  • Duplicate Prevention: HashSet.Contains() check is just as effective as LINQ
  • Single Admin Context: All operations happen in one PowerShell invocation
  • No Growing Exclusion Lists: Only genuinely new paths get added

Fixes #2930

…ipse-platform#2930

Since the script to add an exclusion to Windows Defender seems overly complex, this script replaces the complex LINQ-based exclusion check with a more idiomatic and simpler version PowerShell implementation.

Fixes eclipse-platform#2930
@HannesWell
Copy link
Member

Thank you for this contribution. The changes look good too me and the script indeed looks cleaner. I'm not very familiar with Powershell and that was what I came up with after searching the internet a bit.

However, I could confirm that @fdcastel's objection is correct and this script could be even simpler.
If he doesn't want to contribute the simplification by himself, you could update this PR accordingly, but I would await his reaction first.

@IamLRBA
Copy link
Author

IamLRBA commented Apr 27, 2025

Thank you for this contribution. The changes look good too me and the script indeed looks cleaner. I'm not very familiar with Powershell and that was what I came up with after searching the internet a bit.

However, I could confirm that @fdcastel's objection is correct and this script could be even simpler. If he doesn't want to contribute the simplification by himself, you could update this PR accordingly, but I would await his reaction first.

Thanks for your feedback @HannesWell, If @fdcastel approves I can proceed to update the PR...as per your guidance ofcourse!
Cheers!

@fdcastel
Copy link

fdcastel commented Apr 28, 2025

Apologies for the delay (I was abroad).

I agree with @HannesWell that the script can be simplified even further.

@IamLRBA Based on my tests (and I believe @HannesWell can confirm as well), just using the call

Add-MpPreference -ExclusionProcess $pathsToExclude

should be sufficient. There is no need for any if statements or for instantiating a new Collections.Generic.HashSet[String].

@IamLRBA
Copy link
Author

IamLRBA commented Apr 30, 2025

Thank you for the feedback @fdcastel . You're right upon re-testing with just: Add-MpPreference -ExclusionProcess $pathsToExclude, the command handles duplicates cleanly without throwing errors. I’ll simplify the script accordingly and update the PR shortly.

@fdcastel, I've updated the script to simplify it as suggested. It now directly uses `Add-MpPreference -ExclusionProcess $pathsToExclude` without the extra conditionals or set creation. Let me know if anything else needs tweaking.
Thanks!
cc @HannesWell
@IamLRBA
Copy link
Author

IamLRBA commented Apr 30, 2025

@fdcastel, I've updated the script to simplify it as suggested. It now directly uses Add-MpPreference -ExclusionProcess $pathsToExclude without the extra conditionals or set creation. Let me know if anything else needs tweaking.
Thanks!
cc @HannesWell

@fdcastel
Copy link

Looks good to me! I don’t have a Java setup here to test it out, but the changes seem fine. 🚀 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Script to add an exclusion to Windows Defender may be simplified
3 participants