Description

This is more of a template script than a final solution.

Everyone wants/needs to monitor different statistics from counters, so this could be a start to getting the stats you need.

Usage:

Test-CounterStats -Processor            
Test-CounterStats -Memory            
Test-CounterStats -Disk

 

Usage2:

Test-CounterStats -ComputerName SERVERPI24 -Processor

Pre-requisites:

This script uses another script that converts the Here-Sting into an Array "Convert-HString"

You will need to download that as well.

http://gallery.technet.microsoft.com/scriptcenter/917c2357-2911-4c79-bd06-ab95714de2d4

Script

PowerShell
Edit|Remove
function Test-CounterStats { 
param 
    ( 
     [String[]]$ComputerName = $ENV:ComputerName, 
     [Switch]$Processor = $true, 
     [Switch]$Disk, 
     [Switch]$Memory 
    ) 
 
begin 
    { 
        write-verbose "checking Counter stats" 
    } 
process 
    { 
 
if ($Processor) 
{ 
$Counter = @" 
Processor(_total)\% processor time 
Processor(_total)\% user time 
Processor(_total)\% privileged time 
Processor(_total)\% idle time 
"@ 
}     
 
If ($Disk) 
{ 
$Counter = @" 
LogicalDisk(*)\% idle time 
LogicalDisk(*)\avg. disk queue length 
LogicalDisk(*)\free megabytes 
LogicalDisk(*)\% free space 
"@ 
} 
 
if ($Memory) 
{ 
$Counter = @" 
Memory\Available MBytes 
Memory\% committed bytes in use 
"@ 
} 
 
        # Convert-HString is available here:  
        # http://gallery.technet.microsoft.com/scriptcenter/917c2357-2911-4c79-bd06-ab95714de2d4 
        (Get-Counter -ComputerName $ComputerName -Counter (Convert-HString -HString $Counter)).counterSamples |  
        ForEach-Object { 
        $path = $_.path 
        $hash = @{ 
        Path        = ($path  -split "\\")[-2,-1] -join "-" 
        Item        = $_.InstanceName 
        Value = [Math]::Round($_.CookedValue,2) 
        } 
        New-Object psobject -Property $hash 
        } | select Path,Item,Value 
    } 
end 
    { 
     
    } 
}#Test-CounterStats