Advertisement
slyfox1186

add_or_remove_folder_to_windows_defender_exclusions.ps1

May 1st, 2021 (edited)
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # This script will ask you to enter a folder path
  2. # DO NOT wrap the folder path in quotes
  3.  
  4. Write-Host
  5. Write-Host "Add or Remove a folder in Windows Defender's exclusion list"
  6. Write-Host
  7.  
  8. $FolderPath = Read-Host "Enter a folder path without quotes"
  9.  
  10. $ShowExclusions = {
  11.     Invoke-Expression "Clear-Host; Write-Host"
  12.     Write-Host "Current Excluded Folders"; Write-Host
  13.     Get-MpPreference | Select-Object -Expand ExclusionPath
  14.     Write-Host; Read-Host "Press Enter to exit"
  15.     Invoke-Expression "Clear-Host; Write-Host"
  16. }
  17.  
  18. Invoke-Expression "Clear-Host; Write-Host"
  19.  
  20. Write-Host "Add or Remove: $FolderPath"
  21. Write-Host
  22. Write-Host "[1] Add"
  23. Write-Host "[2] Remove"
  24. Write-Host "[3] Exit"
  25. Write-Host
  26.  
  27. $myChoice = [int](Read-Host "Enter a number")
  28.  
  29. If ($myChoice -eq "1") {
  30.     Add-MpPreference -ExclusionPath $FolderPath
  31.     &$ShowExclusions
  32. }
  33.  
  34. ElseIf ($myChoice -eq "2") {
  35.     Remove-MpPreference -ExclusionPath $FolderPath
  36.     &$ShowExclusions
  37. }
  38.  
  39. ElseIf ($myChoice -eq "3") { Invoke-Expression "Clear-Host; Write-Host" }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement