A Little PowerShell Fun

Did you know that you can query the ORF statistics counters from the Windows PowerShell? This is how it works for the cumulative On Arrival “Tested Emails” counter:

$ORF = New-Object -com “orfeesvc.EnterpriseService”
$cumulative = “”

$sincestartup = “”

$ORF.GetStatisticsEx([ref] $cumulative, [ref] $sincestartup)

$xmldoc = New-Object -com “MSXML.DomDocument”

$xmldoc.loadXML($cumulative)

$node = $xmldoc.selectSingleNode(“/statistics/onarrival/tested”)

$oatested = $node.nodeTypedValue

That’s because PowerShell can invoke COM objects and what ORF returns via the GetStatisticsEx() method is really just XML that can be loaded into the COM-based MSXML parser, and so on…

2 thoughts on “A Little PowerShell Fun

  1. Peter Post author

    I’ve heard about PowerShell (that time Monad) before Exchange 2007 and liked it from the beginning. The trick with PowerShell is that *everything* is an object in the shell. For instance, when you query the list of services (“get-service”), you get a list of service objects (System.ServiceProcess.ServiceController objects) that have methods and properties. For instance, you can start the ORF Service using “(Get-Service vsorfee).Start()”. Sure, “net start” does it pretty well, but if you check the properties and methods (“Get-Service vsorfee | get-member”) you’ll see that you can do a lot more than just starting or stopping a service–modify startup type, description, etc. And as everything is an object, you can do things like get-service | format-table ServiceName, Status, ServiceType, without the get-service cmdlet supporting any type of formatting.

    Check out http://en.wikipedia.org/wiki/Windows_PowerShell for more examples.

Leave a Reply

Your email address will not be published. Required fields are marked *

AlphaOmega Captcha Classica  –  Enter Security Code