Skip to content

Instantly share code, notes, and snippets.

@RickStrahl
Created October 5, 2018 19:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RickStrahl/1f358b4974232dcd661883b72c780fba to your computer and use it in GitHub Desktop.
Save RickStrahl/1f358b4974232dcd661883b72c780fba to your computer and use it in GitHub Desktop.
Turn Defender Real-Time Protection On and Off

Defender's real time protection can significantly slow down disk and IO bound operations on Windows, so if you're doing disk intensive work or stress tests I find turning off Defenders Real Time Protection can improve performance drastically.

The following Powershell script provides a quick way to turn Powershell Real Time protection on and off quickly. Dump this file into a folder on your path to quickly turn.

##################################################
# Turn Defender Real Time Monitoring off

# turns defender real time monitoring -on or -off 
# Has to run under an Admin prompt
#
# Syntax:
#
#    Defender        - turns Monitoring off (default)
#    Defender -off   - turns Monitoring off
#    Defender -on    - turns Monitoring on
##################################################


param(
    [switch] $on = $false,
    [switch] $off = $false
)

$setTo = $true;

if ($on.Equals($true)) {
    $setTo = $false
}
if ($off.Equals($true)) {
    $setTo = $true
}

Write-Host "Defender Real Time Protection"

if ($setTo.equals( $true)) {
    "Set to: Off"
}
else {
    "Set to: On"
}

Set-MpPreference -DisableRealtimeMonitoring $setTo

# Delay to let the settings take
Start-Sleep -MilliSeconds 1000

$defenderOptions = Get-MpComputerStatus
if($defenderOptions) {
    $setting = "On"
    if (-not $defenderOptions.RealTimeProtectionEnabled ) {
        $setting = "Off"
    }
    Write-Host  "Actual Setting: "  $setting
}

Additional things you should do:

  • Create Exclusion Folders in Defender
    • Development folders
    • Development Tools folders (Visual Studio, MSBuild, Resharper)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment