Level Verified

Windows Monitor - Security Center Script

Checks antivirus and firewall settings on Windows devices via Security Center, flagging any disabled or missing security products. Ideal for a script-based monitor that triggers alerts or automatic remediation if an issue is found.

Import into Level

Problem overview

Many organizations struggle to ensure that essential security features, like antivirus and firewall protections, remain consistently enabled and up-to-date on all Windows endpoints. This script addresses that challenge by systematically detecting issues at the system level, allowing IT professionals and MSPs to fix vulnerabilities before they result in security incidents.

PowerShell 100s timeout Runs as Local system Windows
<#
This resource is provided as a convenience for Level users. We cannot 
guarantee it will work in all environments. Please test before deploying 
to your production environment. We welcome contributions to our community 
library

Level Library
https://level.io/library/script-windows-monitor-av
#>

# Initialize a variable to track the overall security health
$securityHealthOk = $true

# Function to check the security health status from the Security Center
function Check-SecurityHealth {
    try {
        # Check Antivirus status
        $antivirusProducts = Get-WmiObject -Namespace "ROOT\SecurityCenter2" -Class "AntiVirusProduct"
        if ($antivirusProducts) {
            foreach ($product in $antivirusProducts) {
                Write-Host "Antivirus Name: $($product.displayName)"
                # Interpret productState for demonstration; you may need specific checks here
                if ($product.productState -match "262144" -or $product.productState -match "266240") {
                    Write-Host "Antivirus Status: Enabled and up to date"
                }
                else {
                    Write-Host "Antivirus Status: Disabled or out of date"
                    $global:securityHealthOk = $false
                }
            }
        }
        else {
            Write-Host "No Antivirus product detected."
            $global:securityHealthOk = $false
        }

        # Check Firewall status
        $firewallProducts = Get-WmiObject -Namespace "ROOT\SecurityCenter2" -Class "FirewallProduct"
        if ($firewallProducts) {
            foreach ($product in $firewallProducts) {
                Write-Host "Firewall Name: $($product.displayName)"
                # Example check; adjust based on actual requirements
                if ($product.productState -match "262144") {
                    Write-Host "Firewall Status: Enabled"
                }
                else {
                    Write-Host "Firewall Status: Disabled"
                    $global:securityHealthOk = $false
                }
            }
        }
        else {
            Write-Host "No Firewall product detected."
            $global:securityHealthOk = $false
        }

        # Check for other security products as needed...

    }
    catch {
        Write-Host "An error occurred querying the Security Center."
        $global:securityHealthOk = $false
    }
}

# Execute the security health check
Check-SecurityHealth

# Determine script exit based on overall security health
if ($securityHealthOk) {
    Write-Host "SUCCESS: All security features are active and in good standing."
    exit 0
}
else {
    Write-Host "ERROR: One or more security features are disabled or in a bad state."
    exit 1
}

The script queries the Windows Security Center for antivirus and firewall status, verifying if these protections are active and up to date. If an issue is detected—for example, an out-of-date antivirus or a disabled firewall—it sets a flag that triggers a non-zero exit code, ideal for generating alerts in Level. This output can then prompt a remediation workflow to re-enable or update these critical security products. By offering a simple “all-clear” or “problem-found” exit state, the script seamlessly integrates with your broader security monitoring strategy.

Use cases

  • Ensuring antivirus and firewall remain consistently enabled
  • Automating security checks on remote endpoints
  • Triggering an alert or remediation workflow in Level if a vulnerability is detected
  • Periodically auditing security status to uphold compliance

Recommendations

  • Configure a script-based monitor in Level to run this script regularly, ensuring prompt detection of any disabled or outdated security features
  • Pair with an automation remediation workflow that attempts to re-enable antivirus or firewall if issues are discovered
  • Test in a non-production environment to ensure the checks align with your antivirus product’s specific productState values
  • Adjust productState checks in the script for any custom antivirus or firewall product that might report different codes

Frequently asked questions.

What if my antivirus or firewall uses different productState codes?

You can modify the matching logic in the script to account for the codes used by your specific security product.

Does this script require elevated privileges?

It does not require manual elevation because scripts run via Level are executed with the necessary System-level privileges on Windows.

Can I extend this script to check additional security products like anti-malware or intrusion detection systems?

Absolutely. Simply expand the logic to query more WMI classes or additional productState values within the script.

How do I respond if the script exits with a non-zero code?

Level can automatically trigger alerts, send notifications, or run follow-up actions (e.g., re-enabling the firewall) when the script returns an error code.

Ready when you are.

No credit card. No sales call. Just sign up and start managing.