I use Perl to interrogate our SMS database via WMI quite a bit. On this occasion, I want to extract the count of items in a table but can't get Perl to reveal the results!
We start with the normal connection to WMI...
# Connect to WMI on reporting server
#
my $SWbemLocator = Win32::OLE->new("WbemScripting.SWbemLocator") or
FatalCOMError("Can't open WbemScripting object");
my $SWbemServices = $SWbemLocator->ConnectServer($Server, "root/sms/si
+te_$SiteCode") or
FatalCOMError("Can't connect to server: $Server");
If I then submit a "straight" query...
# Get count of clients in collection
my $WQL = q/select * from SMS_CM_RES_COLL_CEN01562/;
$Colln = $SWbemServices->ExecQuery($WQL,"WQL",16) or FatalErr("Exe
+cQuery for Clients failed",1);
$count = $Colln->{Count};
...$count contains the count of items in the collection. Unfortunately, on a large collection, this can be a bit slow. Ideally, I'd use the count(*) WQL command like so;
# Get count of clients in collection
my $WQL = q/select count(*) from SMS_CM_RES_COLL_CEN01562/;
$Colln = $SWbemServices->ExecQuery($WQL,"WQL",16) or FatalErr("Exe
+cQuery for Clients failed",1);
The problem that I have with this code is that, no matter what I try, I can't get to the actual result!
If I try the same query on WbemTest, I get a single-line answer that shows the correct answer. How do I get to it in Perl?
Can anyone help?
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.