Back to Resources
Level
Script
Security
Many organizations struggle to ensure reliable, ongoing antivirus protection on Windows systems, including those running third-party security tools. This script taps into Windows Security Center to confirm whether an AV product—be it Windows Defender or a properly registered third-party solution—is active, helping IT professionals and MSPs maintain a consistent layer of endpoint security.
It queries Windows Security Center for any recognized antivirus product status, including real-time protection. If antivirus coverage is confirmed as active, the script returns a success. If not, or if real-time scanning is disabled, it exits with an alert code, enabling Level to trigger a notification or remediation task. By leveraging system-level permissions, it works seamlessly under the hood without additional user intervention, ensuring straightforward monitoring and compliance checks.
1<#
2This resource is provided as a convenience for Level users. We cannot
3guarantee it will work in all environments. Please test before deploying
4to your production environment. We welcome contributions to our community
5library
6
7Level Library
8https://level.io/library/script-windows-check-av
9#>
10
11# Initialize a variable to track if antivirus protection is active
12$antivirusActive = $false
13
14# Function to check the status of Windows Defender Antivirus
15function Check-AntivirusStatus {
16 $status = Get-MpComputerStatus
17 $antivirusEnabled = $status.AntivirusEnabled
18 $realTimeProtection = $status.RealTimeProtectionEnabled
19
20 if ($antivirusEnabled -eq $true -and $realTimeProtection -eq $true) {
21 Write-Host "Antivirus and real-time protection are ENABLED."
22 $global:antivirusActive = $true
23 }
24 elseif ($antivirusEnabled -eq $true) {
25 Write-Host "Antivirus is ENABLED, but real-time protection is DISABLED."
26 }
27 else {
28 Write-Host "Antivirus is DISABLED."
29 }
30}
31
32# Check antivirus status
33Check-AntivirusStatus
34
35# Determine script exit code based on antivirus status
36if ($antivirusActive) {
37 Write-Host "SUCCESS: Antivirus protection is active."
38 exit 0
39}
40else {
41 Write-Host "ALERT: Antivirus protection is not fully active."
42 exit 1
43}
44
Windows - Check AV
This script checks the status of Windows Defender Antivirus, including whether antivirus and real-time protection are enabled. It outputs the status, updates a global variable if both are active, and exits with a success or alert code based on the overall antivirus protection status.
PowerShell
100
Local system
Explore more automations, scripts, and policies to further enhance your IT operations.