How do i exclude a long list of programs in powershell or cmd for windows defender
- User
How do i exclude a long list of programs in powershell or cmd for windows defender
- Assistant
To exclude a long list of programs or file paths from Windows Defender scans, you can use the PowerShell cmdlet
Add-MpPreference. However, you should be cautious when adding exclusions, as this might make your system vulnerable to threats if you exclude important files or folders.First, let's assume you have a text file
exclusions.txtthat contains a list of paths to exclude, one per line, like this:C:\path\to\program1.exe C:\path\to\folder2\ C:\another\path\to\exclude\ ...Now, you'll want to read the list in PowerShell and add each of the paths as an exclusion to Windows Defender:
# Run PowerShell as an administrator $exclusions = Get-Content -Path "C:\path\to\exclusions.txt" foreach ($exclusion in $exclusions) { Add-MpPreference -ExclusionPath $exclusion }This PowerShell script reads every line from your exclusion list and adds them one by one to the Windows Defender exclusion list.
Remember to run PowerShell as an administrator to make sure you have the necessary permissions to change Windows Defender settings.
If you would rather do this in a Command Prompt (
cmd.exe), you will need to call PowerShell from your batch file or command line:@echo off FOR /F "tokens=*" %%G IN (exclusions.txt) DO ( powershell.exe -Command "Add-MpPreference -ExclusionPath '%%G'" )This
FOR /Floop reads lines fromexclusions.txtand for each line, calls PowerShell to add the exclusion.Please be careful with the paths you exclude. Excluding important system files, folders, or applications could potentially leave your system unprotected against malware that targets those locations.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.