Script 1 - To add folders to exclusions
Copy the following code to Notepad and save it as "add_excl.ps1" in "C:\Scripts"
$foldersToExclude = @(
"C:\Windows",
"C:\Program Files (x86)\Steam"
)
# Add folder exclusions
Write-Host "Adding folder exclusions..."
foreach ($folder in $foldersToExclude) {
Add-MpPreference -ExclusionPath $folder
}
Script 2 - To remove all folders from exclusions
Copy the following code to Notepad and save it as "remove_excl.ps1" in "C:\Scripts"
$Paths=(Get-MpPreference).ExclusionPath
foreach ($Path in $Paths) { Remove-MpPreference -ExclusionPath $Path -Verbose}
To execute the script, create shortcuts to the script with the following targets:
powershell.exe "C:\Scripts\add_excl.ps1"
powershell.exe "C:\Scripts\remove_excl.ps1"
Right-click on the appropriate shortcut and click "Run as administrator".