#This works only if Defender has not been disabled on the system. $proc = Get-Process -Name SecurityHealthSystray -ErrorAction SilentlyContinue if ($null -ne $proc) { Write-Output "desktop-active" exit 0 } else { Write-Output "desktop-not-active" exit 0 }