I've created the following script and it seems to be mostly working with a few exceptions. The idea is that I want it it watch a specific queue and alert if there are more than 100 messages in the queue. First issues is that I can't figure out how to make it choose the server name that the SAM is assigned to, so right now I have a static server name entry there.Second issues is that it's telling me it doesn't like the format, but I don't understand why. Any assistance anyone can offer would be greatly appreciated!
# $UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri server.fakedomain.com/.../ -Authentication Kerberos -Credential '${CREDENTIAL}'
Import-PSSession $Session -DisableNameChecking
# Run the Get-Queue command and store the output in a variable
$queues = Get-Queue
# Filter the queues based on DeliveryType
$smartHostQueue = $queues | Where-Object { $_.DeliveryType -eq "SmartHostConnectorDelivery" }
# Display the MessageCount for the SmartHostConnectorDelivery queues
Write-Host "MessageCount for SmartHostConnectorDelivery queues: $($smartHostQueue.MessageCount)"
if ($smartHostQueue.MessageCount -ge 100)
{
Write-Host "Message: Less than 100 messages found waiting in queue";
Write-Host "Statistic: $smartHostQueue.MessageCount";
Exit 0;
}
Write-Host "Message: $smartHostQueue.MessageCount";
Exit 1;
I'll attach a screen shot of it tells me when I test it. 