Answered problem with write-host command

  • Wednesday, December 12, 2012 5:53 PM
     
     

    I am very new to scripting, but have pieced this script togoether.  The problem is that on all line #8 it just displays "Microsoft.PowerShell.Commands.GenericMeasureInfo.count".  Other lines do to, but specifically line #8.

    If I run the commands manually from the prompt and just type $Total it works, but with the Write-host command it does not.

    Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010 -ErrorAction SilentlyContinue
    $CasServers = Get-Content "C:\batch\Cas.txt"
    $yesterday = get-date -format d (get-date).AddDays(-1)
    $today = get-date -format d
    function checkmail(){
     Write-Host "Checking Messages Send and Recieved from $yesterday to $today" -ForegroundColor Green
     $Total = Get-TransportServer | Get-MessageTrackingLog -Resultsize unlimited -Start "$yesterday 12:00AM" -End "$today 12:00AM" | select-object -unique messageid | Measure-object
     Write-Host "$Total"
     Foreach ($cas in $CasServers){
      $pingStat = Get-WmiObject -class Win32_PingStatus -Filter "Address = '$Cas'" | select StatusCode
      if ($pingStat.StatusCode -eq 0){
       Write-Host "Checking $Cas" -ForegroundColor Cyan
       $Received = Get-Messagetrackinglog -server $Cas -EventID "Receive" -ResultSize unlimited -Start "$yesterday 12:00AM" -End "$today 12:00AM" | select-object -unique messageid | Measure-object
       Write-Host "Received $Received.count"
       $msgs = Get-Messagetrackinglog -server $Cas -ResultSize unlimited -Start "$yesterday 12:00AM" -End "$today 12:00AM" | select-object -unique messageid | Measure-object
       Write-Host $msgs.count  
      }else{
       Write-Host "Server $Cas did not reply to ping" -ForegroundColor Red
      }
     }
    }

    checkmail

    Thanks so much for all assistance!!

All Replies

  • Wednesday, December 12, 2012 5:58 PM
    Moderator
     
     Answered Has Code

    Presumably line 8 is this line:


    Write-Host "$Total"

    Your $Total variable contains a MeasureInfo object. The MeasureInfo object has a Count property. If you want to output the object's Count property, then just do so:


    write-host $Total.Count

    Bill

    • Marked As Answer by David-Mac Wednesday, December 12, 2012 6:58 PM
    •  
  • Wednesday, December 12, 2012 5:59 PM
    Moderator
     
     Answered Has Code

    Try this:

    Write-Host "$($Total.count)"


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "

    • Marked As Answer by David-Mac Wednesday, December 12, 2012 6:59 PM
    •  
  • Wednesday, December 12, 2012 6:59 PM
     
     
    I tried both suggestions and both worked.  Thanks so much!!!  You guys are great!!