Get Defender Version Powershell

Hello,

i have PowerShell below to get defender last update

with same script why SAM return N/A for variable message.av ?

  • Hi hs08,

    it's probably because $output.SignatureLastupate is null. 

    $test = Get-MpComputerStatus | Select-Object AntispywareSignatureLastUpdated
    $av = $test.AntispywareSignatureLastUpdated
    
    If ($av)
       {
        Write-Host "Statistic.av: 1"
        Write-Host "Message.av: $($av)"
       }
    Else
       {
        Write-Host "Statistic.av: 0"
        Write-Host "Message.av: Empty variable"
       }

  • Yaquaholic, was almost there. :-)

    Update: changed Statistic Code's, got them in the wrong order.

    Here some code that should help you out.
    Returns an Statistic Warning (1) NO AV Signature detected, Statistic Critical (2) an Error running script and a Statistic Up (0) AV Signature found.
    Returned an Exit Code as the link below. Exit Code Up (0) AV Signature found, Exit Code Warning (2) NO AV Signature detected and Exit Code Down (1)  error running script

    Remember your Exit Code is different to your Statistic Code. Exit Code will give you a UP / DOWN / WARNING / CRITICAL / OTHER code, where as a Statistic Code you can set a Threshold against.

    Report status through exit codes in SAM script monitors

    Try
    {
        $output = Get-MpComputerStatus | Select-object AntivirusSignatureLastUpdated 
        $av = $output.AntivirusSignatureLastUpdated
    
        if ([System.string]::IsNullOrEmpty($av))
        {
            $Message = "No Antivirus Signature detected"
            $Stat = 1 # Statistic code Warning
            $ExitCode = 2 # Exit Code for Warning
        }
        Else
        {
            $Message = "Antivirus Signature Date - {0}" -f ($av).ToString()
            $Stat = 0 Statistic Code Good
            $ExitCode = 0 # Exit Code for UP
        }
    }
    Catch 
    {
        $Message = "Error detected"
        $Stat = 2 # Statistic code Critical
        $ExitCode = 1 # Exit Code for Down
    }
    Write-Output ([System.String]::Format("Message.AV: {0}", $message))
    Write-Output ([System.String]::Format("Statistic.AV: {0}", $stat))
    Exit $ExitCode