I have the following code to simply check if an Exchange database has been dismounted. It works fine running from the Orion server, but when I test this as a Powershell Monitor, it always says nothing is dismounted. I've tried several things, but I'm baffled. I'm even just pulling anything that isn't mounted. I've tried different variations, but it always returns "No dismounts" even though there is a test db that IS dismounted. Again, running the code on the Orion server in ISE works fine.
add-pssnapin Microsoft.Exchange.Management.PowerShell.E2010
$status = Get-MailboxDatabase -Server $args[0] -Status | where {$_.Mounted -eq $false}
if ($status) {
$name = $status.name
write-host "Message: $name is dismounted"
write-host "Statistic: 1"
exit 1;
}
if (!$status) {
write-host "Message: No dismounts"
write-host "Statistic: 0"
exit 0;
}