Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

WMI query Exchange Server with Perl

by Ice-Breaker (Novice)
on Dec 17, 2012 at 15:05 UTC ( [id://1009182]=perlquestion: print w/replies, xml ) Need Help??

Ice-Breaker has asked for the wisdom of the Perl Monks concerning the following question:

I've been using WMI a lot to get information from servers and I've been getting good results (generic though like processor state, hdd, logged on users, process lists etc ) Now I have a specific task to query some specific data from an Exchange Server 2010 Data like the one you might get from the performance monitor and health check like Active Mailbox Delivery Queue, send queue size, receive queue size, SMTP Current Connections and the list goes on and on. Now I've been doing some research and i've found some articles and found that this class is supposed to have the data I need : root\MicrosoftExchangeV2 I'm having a hard time coding this and I've found some vb examples that I tried to convert in perl modules but nothing seem to work. Any start up example is appreciated ps: on the exchange server wmi seems to be not accesable from remote (so i run this locally)
#!/usr/bin/perl use Win32::OLE('in'); use constant bFlagReturnImmediately => 0x10; use constant bFlagForwardOnly => 0x20; #use warnings; use Win32::OLE::Enum; my $comp = "."; my $oWMIService_ = Win32::OLE->GetObject( "winmgmts:impersonationLevel +=impersonate}!\\\\$comp\\ROOT\\MicrosoftExchangeV2") or die "problem" +; my $colItems_ = $oWMIService_->ExecQuery ( "Select * from Exchange_Lin +k", "WQL", bFlagReturnImmediately | bFlagForwardOnly); foreach my $objItem_ (in $colItems_){ print $objItem_->{StateRemote}; }

Replies are listed 'Best First'.
Re: WMI query Exchange Server with Perl
by Anonymous Monk on Dec 17, 2012 at 15:07 UTC

    What is the problem with what you posted? Why not use DBD::WMI?

      Hi There, A tool I have used a lot in the past is Scriptomatic (from the Microsoft Scripting Guys). It generates basic scripts with WMI queries once you have chosen your WMI Class. I am not sure if your class is in there but it may be worth a try. Scripts are generated in various scripting languages including Perl. As far as I know Scriptomatic only runs on a Win platform.

      The problem is with the exchange wmi classes, when I run default wmi queries like Select * from Win32_ComputerSystem they run fine, but with the exchange classes its a bit of a problem and the code fails at die "problem".Win32::OLE->LastError;
      problemWin32::OLE(0.1703) error 0x80041021 after character 0 in "winmgmts:{impersonationLevel=impersonate}!\\.\ROOT mv2pplications +←xchange:E xchangeQueue" at test_wmi.pl line 11.
      Is there any way of accessing exchange performance classes with perl in any way? I've done some reading about it and the documentation is around but there are no samples and not quite what I'm looking for..

        First, do it using the wmic command. Once you have worked out how to do it there, doing the same using OLE will either be trivial, or indicate a problem with Win32::OLE


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        RIP Neil Armstrong

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1009182]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-26 00:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found