System.Diagnostics.PerformanceCounterCategory
(1)
System.Diagnostics.PerformanceCounter
(1)
MSExchangeTransport
(1)
MSExchange
(1)
SMTP
(1)
Proc.GetCounters
(1)
MultiInstance
(1)
CategoryName
(1)

Is there a way of accessing performance objects ?

Asked By ian_
20-Jul-07 06:24 AM
Is there a way to access performance counter objects in PowerShell ?

I wish to access

MSExchange Transport Server SMTP Send : Messages Sent Total
MSExchange Transport Server SMTP Receive : Messages Received Total

Which is pretty obvious what they contain (Exchange 2007).

I have a scheduled PowerShell script that runs twice a day that e-mails
interesting Exchange statistics to the Admins to confirm Exchange is all
working and happy. Just adding these two values would be useful.

Is there a way of accessing performance objects ?

Asked By Rich
20-Jul-07 07:28 AM
There is an example of accessing performance counters here

http://www.leeholmes.com/blog/AccessingPerformanceCountersInPowerShell.aspx




--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk

How do I access (or display their names) the individual items of this object?

Asked By ian_
20-Jul-07 08:04 AM
How do I access (or display their names) the individual items of this object?

Doing this clearly gets the right object:-

new-object
System.Diagnostics.PerformanceCounterCategory("MSExchangeTransport
SmtpReceive") | fl

and outputs:-

CategoryName : MSExchangeTransport SmtpReceive
CategoryHelp : Performance counters for Edge SmtpReceive Component
CategoryType : MultiInstance
MachineName  : .


How can I find the items names? and then select them ?

Ian

If you want to see the counters for a category with a single instance you can

Asked By Rich
20-Jul-07 08:34 AM
If you want to see the counters for a category with a single instance you can
do it like this

$mem = New-Object System.Diagnostics.PerformanceCounterCategory("Memory")
$mem.GetCounters() | Select CounterName

If there are multiple instances of a category try this

$proc = New-Object System.Diagnostics.PerformanceCounterCategory("Processor")
$proc.GetCounters(0) | Select CounterName

Replace the 0 with whatever instance you want to work with


--
Richard Siddaway
Please note that all scripts are supplied "as is" and with no warranty
Blog: http://richardsiddaway.spaces.live.com/
PowerShell User Group: http://www.get-psuguk.org.uk
I also have an entry on my old blog with a good example how this works
Asked By /\\/\\o\\/\\/ [MVP]
20-Jul-07 12:36 PM
I also have an entry on my old blog with a good example how this works :

http://mow001.blogspot.com/2005/12/getting-performancemonitor-info-from.html

Greetings /\/\o\/\/
http://thePowerShellGuy.com
Is there a way of accessing performance objects ?
Asked By ian_
25-Jul-07 07:14 AM
Thanks for the help, this is what I ended up with:-

$c1 = new-object System.Diagnostics.PerformanceCounter("MSExchangeTransport
SmtpReceive","Messages Received Total","from POP3 forwarder")
$c2 = new-object System.Diagnostics.PerformanceCounter("MSExchangeTransport
SmtpSend","Messages Sent Total","to internet")
$c3 = new-object System.Diagnostics.PerformanceCounter("MSExchangeTransport
SmtpReceive","Bytes Received Total","from POP3 forwarder")
$c4 = new-object System.Diagnostics.PerformanceCounter("MSExchangeTransport
SmtpReceive","Message Bytes Received Total","from POP3 forwarder")
$c5 = new-object System.Diagnostics.PerformanceCounter("MSExchangeTransport
SmtpSend","Message Bytes Sent Total","to internet")
$c1, $c2, $c3, $c4, $c5 | ft CounterName, RawValue -Autosize

Works fine, though I assume someone will be along in a minute with something
shorter and more elegant.

I am having issues with the System Up Time counter in that it doesn't change.
$a = new-object System.Diagnostics.PerformanceCounter("System","System Up
Time")
$a.RawValue

Produces a static value ?

Ian
Post Question To EggHeadCafe