Search code examples
powershellwindows-server-2008powershell-2.0exchange-serverexchange-server-2007

Why won't the .Count method work in a EMS/Powershell session against this output?


I am working on a monitoring script for exchange 2007 LCR and SCR replication to automate some of my daily work and make sure other people can see if something is wrong. My code is below and I have a condition where one of the databases is above 2000 logs in the replay queue. I know the resto of the script works because if I check the output without the .count, it does return the database whose transaction log replay queue is too high. Can someone explain to me what I am doing wrong and why I can't count the output?

#SCR Replay Queue Length Check
IF (($SCRstatusTable|? {$_.ReplayQueueLength -ge 2000}).Count -gt 0)
{
  $SCRReplayQueueLengthHealth = "SCR replay queue length check: At least 1 instance 
        is reporting more than 2000 queued logs.  Refer to detailed logs for more information."
}
ELSE
   {
            $SCRReplayQueueLengthHealth = "SCR replay queue length check:  No instances
            currently reporting more than 2000 logs queued for replay."
         }

Any help is greatly appreciated! I am thinking it is a syntax thing as I have used the .count method to count other collection output without a problem.


Solution

  • Try forcing it into an array. I have illustrated the difference with the get-process cmdlet below:

    PS > (get-process | select -first 1).count   #no count
    PS > @(get-process | select -first 1).count
    1
    

    So you have to do something like:

    @($SCRstatusTable|? {$_.ReplayQueueLength -ge 2000}).Count