cd "C:\Program Files\Tenable\Nessus Agent"
$NessusStatus = .\nessuscli agent status
$NessusStatusString = $NessusStatus | out-string

if ($nessusstatus[2].Contains("disconnected")) {
    Write-Host "Nessus Agent is Disconnected and requires remediation "$nessusstatus[2]
    exit 1
}
elseif ($nessusstatus[2].Contains("authentication error")) {
    Write-Host "Nessus Agent is in authorization error state and requires remediation "$nessusstatus[2]
    exit 1
}
elseif ($nessusstatus[2].Contains("Not linked to a manager")) {
    Write-Host "Nessus Agent is Not linked to a manager "$nessusstatus[2]
    exit 1
}
elseif ($nessusstatus[2].Contains("Link status: Connected to paptennm001.ccx.carecentrix.com:8834")) {
    Write-Host "Nessus Agent is connected and healthy "$nessusstatus[2]
    exit 0
}
else {
    Write-Host "Nessus Agent in an unknown status "$nessusstatus[2]
    exit 1
}