ScriptSecurityWindows

Check Windows Security Center

Flag disabled or outdated antivirus and firewall products reported by Security Center.

See what you’re importing.

Read-only preview

PowerShell Timeout 100s Runs as Local system
<#
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
}

Before you run it.

  1. Configure a script-based monitor in Level to run this script regularly, ensuring prompt detection of any disabled or outdated security features

  2. Pair with an automation remediation workflow that attempts to re-enable antivirus or firewall if issues are discovered

  3. Test in a non-production environment to ensure the checks align with your antivirus product’s specific productState values

  4. Adjust productState checks in the script for any custom antivirus or firewall product that might report different codes

More about this resource.

What it does

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, such as 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.

When to use it
  • 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
The problem it solves

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.

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.