Trouble getting this to do what I'd like it to do

by Mar 27, 2013

I'm very new to Powershell scripting but I have some of the basics kinda mashed out. Basically I'm writing a report thats looking into the MSMQ system and reporting back the Queue values. 

For the most part, it works. However what I'm trying to do is color code the report based on a threshold. So I know I need to push these values through a conditional of some sorts.

I think in my foreach, the results of $_.MessagesinQueue are returning null values.

So I decided to write the value of $_.MessagesinQueue inside each of the if's and the output returned nothing for each line.  So I know I'm having a case of the dumb here. Any tips would be greatly appreciated.

Get-WMIObject Win32_PerfRawData_MSMQ_MSMQQueue -computerName $server | ? {($_.Name -like "* a*" ) -and ($_.Name -notlike "os:*"  ) -and ($_.Name -notlike "*restore*")} |
       ConvertTo-Html -Head "Archival Queues" -Property Name, MessagesinQueue |
       
       ForEach { $_.MessagesinQueue}{
            $tempnum = $_.MessagesinQueue
            if($tempnum.MessagesinQueue -gt 2000) {
              Write-Host $_.MessagesinQueue
            
              $_ -replace "<td>" , "<td><font color=#2EFE2E>"}
            elseif($tempnum.MessagesinQueue -lt 2001) {
            
              $_ -replace "<td>" , "<td><font color=#FF0000>"}
            }