I created a PowerShell script that looks at Exchange mailbox database health and returns a 1 for healthy/mounted and a 0 for suspended. The script works well; trouble is some of our Exchange server have many databases so the output can be up to 8 number
1's.
I would like to return a single number 1 if ANY mailbox database is not healthy/mounted on a server.
I'm stuck.
Script:
Any suggestions would be great!
#Get PS version
#$PSVersion = $Host.Version.Major
Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
. $env:ExchangeInstallPath\bin\RemoteExchange.ps1
Connect-ExchangeServer -auto
Get-MailboxDatabaseCopyStatus | Foreach-Object {
If ($_.Status.ToString() -eq "Mounted" -or $_.ContentIndexState.ToString() -eq "Healthy")
{
# Write-Host "$($_.Name) - $($_.Status) - $($_.ContentIndexState) - 1" -ForegroundColor Green
# Write-Output "$($_.Name) - $($_.Status) - $($_.ContentIndexState) - 1"
# $status = 1 is Mounted and Healthy
$status = 1
}
Else
{
# Write-Host "$($_.Name) - $($_.Status) - $($_.ContentIndexState) - 0" -ForegroundColor red
# Write-Output "$($_.Name) - $($_.Status) - $($_.ContentIndexState) - 0"
# $Status = 0 is not Mounted and Suspended
# $status = 0
}