Skip to content
TheChatArchiveThe Chat Archive
gpt-4-1106-preview· openaiHugging Face Suzhen/CodeChat

How do i exclude a long list of programs in powershell or cmd for windows defender

  1. User

    How do i exclude a long list of programs in powershell or cmd for windows defender

  2. 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.txt that 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 /F loop reads lines from exclusions.txt and 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.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.