Answered by:
Powershell and performance counter cooked value

Question
-
Hi
Is there a better / faster way to retrieve the cookedvalue from a performance counter than below?
$getRPCReq = Get-Counter "\\server\MSExchangeIS\RPC Requests" -sampleinterval 5
$RPCReqcs = $getRPCReq.countersamples | where {$_.path -match "RPC Requests"}
$RPCReq = $RPCReqcs.cookedvalueI need the cookedvalue only as I write it to a webpage, eg:
$HTML = "...blah and
<tr><td align=left>MAPI RPC Requests</td>" + $RPCReq + "</td><....Thursday, August 5, 2010 1:10 PM
Answers
-
$getRPCReq = Get-Counter "\\server\MSExchangeIS\RPC Requests" -sampleinterval 5
$RPCReq = $getRPCReq.CounterSamples |Select-Object CookedValue
$HTML = "...blah and
<tr><td align=left>MAPI RPC Requests</td>" + $RPCReq.CookedValue + "</td><....Karl
http://unlockpowershell.wordpress.com
-join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})- Proposed as answer by Boe ProxMVP Friday, August 6, 2010 8:09 PM
- Marked as answer by Shay Levi Sunday, August 8, 2010 11:32 AM
Thursday, August 5, 2010 2:29 PM
All replies
-
$getRPCReq = Get-Counter "\\server\MSExchangeIS\RPC Requests" -sampleinterval 5
$RPCReq = $getRPCReq.CounterSamples |Select-Object CookedValue
$HTML = "...blah and
<tr><td align=left>MAPI RPC Requests</td>" + $RPCReq.CookedValue + "</td><....Karl
http://unlockpowershell.wordpress.com
-join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})- Proposed as answer by Boe ProxMVP Friday, August 6, 2010 8:09 PM
- Marked as answer by Shay Levi Sunday, August 8, 2010 11:32 AM
Thursday, August 5, 2010 2:29 PM -
Thanks :)Thursday, August 5, 2010 3:39 PM
-
Welcome :)
http://unlockpowershell.wordpress.com
-join("6B61726C6D69747363686B65406D742E6E6574"-split"(?<=\G.{2})",19|%{[char][int]"0x$_"})Thursday, August 5, 2010 5:16 PM -
Get-Counter "\\server\MSExchangeIS\RPC Requests" -sampleinterval 5 | Foreach-Object{ $HTML += "<tr><td align=left>MAPI RPC Requests</td>" + $_.CounterSamples[0].CookedValue + "</td><...." }
Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell ToolbarSunday, August 8, 2010 11:31 AM -
Hi Shay
Your method returns
$_.CounterSamples[0].CookedValue
--------------------------------
4I want only the value
4
but it did give me a method to reference the countersamples cooked value directly which is what I was really looking for..
$RPCReq = Get-Counter "\\server\MSExchangeIS\RPC Requests" -sampleinterval 5
$HTML = "...blah and
<tr><td align=left>MAPI RPC Requests</td>" + $RPCReq.{$_.CounterSamples[0].CookedValue} + "</td><....Thanks for your help.
Tuesday, August 10, 2010 8:58 AM -
Are you sure? I get the value only:
PS > Get-Counter "\\server\MSExchangeIS\RPC Requests" -sampleinterval 5 | Foreach-Object{ $_.CounterSamples[0].CookedValue }
4
Shay Levy [MVP]
http://blogs.microsoft.co.il/blogs/ScriptFanatic
PowerShell ToolbarTuesday, August 10, 2010 9:03 AM -
Sorry you are right. I tested without using foreach
so this works nicely..
$RPCReq = Get-Counter "\\server\MSExchangeIS\RPC Requests" -sampleinterval 5 | Foreach-Object{ $_.CounterSamples[0].CookedValue }
$HTML = "...blah and
<tr><td align=left>MAPI RPC Requests</td>" + $RPCReq + "</td><....In my script $HTML contains many values, some with maths applied etc so it is easier for me to continue to do above as opposed to $HTML +=
see..
<font size=2>Exchange 2007 Performance Monitor
<table align=centre>
<colgroup> <col/> <col/> <col/> </colgroup>
<tr><th>Performance Counter</th><th><b>Current Value</th><th><b>Expected Value - hover for info</th></tr>
<tr><td align=left>server Mailbox Logon Latency</td>" + $A1 + $latencytotal + "ms</td><td title='Verifies server functi
<tr><td align=left>server MAPI RPC Requests</td>" + $A2 + $RPCReq + "</td><td title='Indi
<tr><td align=left>server MAPI RPC Avg. Latency</td>" + $A3 + $RPClat + "ms</td><td title='Indicates the RP
<tr><td align=left>server MAPI RPC Ops/sec </td>" + $A4 + $RPCOps + "</td><td title='Should closely correspond to histo
<tr><td align=left>server CCR Copy Queue Length</td>" + $A5 + $CCRCQL + "</td><td title='Shows the number of transactio
<tr><td align=left>server CPU Processor Time </td>" + $A6 + $CPUused + "%</td><td title='5 Sec Sample. Shows the percen
<tr><td align=left>server MEM Available MB's </td>" + $A7 + $MEMavail + "MB</td><td title='Shows the amount
<tr><td align=left>server DISK Avg Reads</td>" + $A8 + $DISKread + "ms</td><td title='5 Sec Sample. For servers with mo
<tr><td align=left>server DISK Avg Writes</td>" + $A9 + $DISKwrite + "ms</td><td title='5 sec Sample. Should be below 1
<tr><td align=left>server DB LOG CheckPointDepth</td>" + $A10 + $LOGcpd + "</td><tThanks again for the help!
Tuesday, August 10, 2010 9:24 AM