Skip to content

Instantly share code, notes, and snippets.

@RoadToDream
Created November 5, 2022 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RoadToDream/808379d2addb4cc0fd36a49b112ca2d7 to your computer and use it in GitHub Desktop.
Save RoadToDream/808379d2addb4cc0fd36a49b112ca2d7 to your computer and use it in GitHub Desktop.
Toggle Defender Real-time Protection.
#####################################################################
# Toggle Defender Real-time Protection
#
# Syntax:
#
# Defender - toggle Real-time Protection (default)
# Defender -state 0/1 - Set Real-time Protection to Enable/Disable
#####################################################################
param(
[int] $state = -1
)
if ($state.equals(-1)) {
$TargetState = $(Get-MpComputerStatus).RealTimeProtectionEnabled
Set-MpPreference -DisableRealtimeMonitoring $TargetState
}
else {
$TargetState=[boolean]($state -xor 1)
Set-MpPreference -DisableRealtimeMonitoring $TargetState
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment