Skip to content

Instantly share code, notes, and snippets.

@melvinsh
Created April 13, 2017 09:23
Show Gist options
  • Save melvinsh/70c74e035e12a9a2dac9e8b5617fbff1 to your computer and use it in GitHub Desktop.
Save melvinsh/70c74e035e12a9a2dac9e8b5617fbff1 to your computer and use it in GitHub Desktop.
Toggle Windows Defender's Real-time Protection
# Run as administrator
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Start-Process powershell.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit
}
$Preferences = Get-MpPreference
if($Preferences.DisableRealtimeMonitoring) {
Set-MpPreference -DisableRealtimeMonitoring 0
} else {
Set-MpPreference -DisableRealtimeMonitoring 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment