http://www.perlmonks.org?node_id=559261

rod has asked for the wisdom of the Perl Monks concerning the following question:

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?