Saltar al contenido
Microsoft scripts

Scripts de Intune

Detectar firmas de Microsoft Defender Antivirus desactualizadas

Revisa si las definiciones de Microsoft Defender Antivirus tienen más de 48 horas. Con exit 1 dispara la corrección que las actualiza.

Antes de correrloSolo lee con Get-MpComputerStatus. Va en pareja con remediate-antivirus-definitions.ps1. El encabezado del script pide un permiso de Graph que el código no usa: corre en el equipo como SYSTEM, sin Graph. La primera vez un administrador de Intune debe confirmar la verificación de licencias de Windows en Remediaciones.

Ejemplo en México

Aseguradora en Mexicali, 70 laptops de agentes que viajan

Las laptops pasan semanas sin red corporativa y sus firmas de antivirus se atrasan.

detect-antivirus-definitions-outdated.ps1

El reporte de la corrección muestra qué laptops estaban atrasadas y cuáles ya se actualizaron.

Cómo implementarlo

  1. En el centro de administración de Microsoft Intune ve a Dispositivos > Administrar dispositivos > Scripts y correcciones (Scripts and remediations) > Remediations > Crear paquete de scripts.
  2. En Configuración sube detect-antivirus-definitions-outdated.ps1 como script de detección y remediate-antivirus-definitions.ps1 como script de corrección.
  3. Deja desactivadas "Ejecutar con las credenciales del usuario" y "Aplicar verificación de firma", asígnalo primero a un grupo piloto y elige la frecuencia.
  4. Revisa en el paquete la pestaña de estado del dispositivo: "Con problemas" son los equipos detectados antes de corregir.
Ver el código completo de detect-antivirus-definitions-outdated.ps1
<#
.TITLE
    Windows Defender Definition Update Detection

.SYNOPSIS
    Detects if Windows Defender antivirus definitions are outdated

.DESCRIPTION
    Checks if Windows Defender definitions are current (within 48 hours).
    Returns exit code 1 if definitions are outdated.

.TAGS
    Remediation,Detection

.REMEDIATIONTYPE
    Detection

.PAIRSCRIPT
    remediate-antivirus-definitions.ps1

.PLATFORM
    Windows

.MINROLE
    Intune Service Administrator

.PERMISSIONS
    DeviceManagementManagedDevices.ReadWrite.All

.AUTHOR
    Ugur Koc

.VERSION
    1.0

.CHANGELOG
    1.0 - Initial version

.LASTUPDATE
    2025-06-09

.EXAMPLE
    .\detect-antivirus-definitions-outdated.ps1

.NOTES
    Runs in SYSTEM context
#>

$ErrorActionPreference = "Stop"
$script:MaxDefinitionAgeHours = 48

try {
    # Get Defender status
    $mpStatus = Get-MpComputerStatus -ErrorAction Stop
    
    # Check definition age
    $now = Get-Date
    $definitionAge = ($now - $mpStatus.AntivirusSignatureLastUpdated).TotalHours
    
    Write-Output "Definition age: $([math]::Round($definitionAge, 1)) hours"
    Write-Output "Last updated: $($mpStatus.AntivirusSignatureLastUpdated)"
    Write-Output "Version: $($mpStatus.AntivirusSignatureVersion)"
    
    if ($definitionAge -gt $script:MaxDefinitionAgeHours) {
        Write-Output "Definitions are outdated (threshold: $script:MaxDefinitionAgeHours hours)"
        exit 1
    }
    
    Write-Output "Windows Defender definitions are up to date"
    exit 0
}
catch {
    Write-Error "Detection failed: $_"
    exit 2
}

# Copia sin cambios de https://github.com/ugurkocde/IntuneAutomation (commit 797bb2e).
# MIT License
#
# Copyright (c) 2025 Ugur Koc | Microsoft MVP
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

Relacionados