troubleshooting Question

query 2 tables w/ like column names, get one result

Avatar of Marketing_Insists
Marketing_Insists asked on
Perl
10 Comments1 Solution533 ViewsLast Modified:
# I'm trying to query two tables (via WMI), but I need to get a single result.
# some of the columns in each table have identical headers, but have different info
# (like 'Name' could be the physical drive name when queried from one table or the letter name
# when queried from another) and I need the info from each.
# right now, the below gives me two reports about the same disk.  How can I just get one report?

use strict;
use Win32::OLE('in');

use constant wbemFlagReturnImmediately => 0x10;
use constant wbemFlagForwardOnly => 0x20;

my @computers = (".");
foreach my $computer (@computers) {
   print "\n";
   print "Computer: $computer\n";


  my $objWMIService = Win32::OLE->GetObject("winmgmts:\\\\$computer\\root\\CIMV2") or die "WMI connection failed.\n";
  my $Win32_LogicalDisk = $objWMIService->ExecQuery("SELECT * FROM Win32_LogicalDisk", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);
  my $Win32_DiskDrive = $objWMIService->ExecQuery("SELECT * FROM Win32_DiskDrive", "WQL", wbemFlagReturnImmediately | wbemFlagForwardOnly);

  foreach $physical (in $Win32_DiskDrive ) {

print "\n\n";

#physical disk info
   print "Physical Drive Name: $physical->{Name}\n";
   print "Model: $physical->{Model}\n";
   }

  foreach $Logical (in$Win32_LogicalDisk ) {

print "\n\n";

#logincal disk info
      print "Letter Name: $Logical->{Name}\n";
      print "Description: $Logical->{Description}\n";
      print "FreeSpace: $Logical->{FreeSpace}\n";
   }
}

__END__

what I want is

   print "Letter Name: $Logical->{Name}\n";
   print "Physical Drive Name: $physical->{Name}\n";
   print "Model: $physical->{Model}\n";
   print "Description: $Logical->{Description}\n";
   print "FreeSpace: $Logical->{FreeSpace}\n";
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 10 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 10 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros