On Fri, 04 Dec 2009 17:10:26 -0800, Michael Ellery <mi...@s2technologies.com> wrote: > Michael wrote: >> Okay - Just to sum up the whole thing. >> >> The original VBScript <<EOF; >> >> Option Explicit >> >> Dim objWMIService, objOV_NodeGroup, objGetRoot, objChildGroups, arrNodes, >> objItem >> >> Set objWMIService = >> GetObject("winmgmts:root\HewlettPackard\OpenView\data") >> >> Set objOV_NodeGroup = objWMIService.Get("OV_NodeGroup") >> Set objGetRoot = objOV_NodeGroup.GetRoot() >> objChildGroups = objGetRoot.GetChildNodeGroups(arrNodes, True) >> >> WScript.Echo "Child Group Count: " & objChildGroups & vbCrLF >> >> For Each objItem In arrNodes >> WScript.Echo "Name: " & objItem.Name >> Next >> EOF >> >> Returns the following: >> >> Child Group Count: 25 >> >> Name: {36716FD8-E600-46FB-90CA-1263E0C62509} >> Name: {38FF8E8E-2DDC-4895-A7EB-0DC7DF50EC25} >> Name: {3E575181-0225-4553-9722-46F841B9FA76} >> Name: {8A412133-F571-42BC-8A66-4B242EB3BAC4} >> Name: {E14D965C-1FBB-40EC-A784-5F9F39F82281} >> Name: OpenView_AIX >> Name: OpenView_External >> Name: OpenView_HPUX >> Name: OpenView_Linux >> Name: OpenView_NNM >> Name: OpenView_OpenVMS >> Name: OpenView_OpenVMS(itanium) >> Name: OpenView_SNMP >> Name: OpenView_Solaris >> Name: OpenView_Tru64 >> Name: OpenView_Unknown >> Name: OpenView_Windows2000 >> Name: OpenView_WindowsNT >> Name: OpenView_WindowsServer2003 >> Name: OpenView_WindowsServer2008 >> Name: OpenView_WindowsVista >> Name: OpenView_WindowsXP >> Name: Root_Special >> Name: Root_Unix >> Name: Root_Windows >> >> And the Perl-Script with the modification <<EOF; >> #!perl >> use strict; >> use warnings; >> use Win32::OLE qw(in with); >> use Win32::OLE::Variant; >> use Data::Dumper; >> >> my $objWMIService = >> Win32::OLE->GetObject("winmgmts:root/HewlettPackard/OpenView/data") or >> die >> "WMI connection failed.\n"; >> if (Win32::OLE-> LastError() != 0) { >> print "Error calling GetObject: " . Win32::OLE->LastError() . "\n"; >> exit 0; >> } >> >> my $objOV_NodeGroup = $objWMIService->Get("OV_NodeGroup"); >> if (Win32::OLE-> LastError() != 0) { >> print "Error calling Get: " . Win32::OLE->LastError() . "\n"; >> exit 0; >> } >> >> my $objGetRoot = $objOV_NodeGroup->GetRoot(); >> if (Win32::OLE-> LastError() != 0) { >> print "Error calling GetRoot: " . Win32::OLE->LastError() . "\n"; >> exit 0; >> } >> >> my $nodes = Win32::OLE::Variant->new(VT_ARRAY|VT_VARIANT, 0); >> #my $nodes = Win32::OLE::Variant->new(VT_VARIANT|VT_BYREF); >> #my $nodes = Win32::OLE::Variant->new(VT_ARRAY|VT_BSTR, 0); >> #my $nodes = Win32::OLE::Variant->new(VT_DISPATCH|VT_BYREF); >> #my $nodes = Win32::OLE::Variant->new(VT_ARRAY|VT_VARIANT|VT_BYREF, 0); >> #my $nodes = Win32::OLE::Variant->new(VT_ARRAY|VT_BSTR|VT_BYREF, 0); >> #my $nodes = Win32::OLE::Variant->new(VT_VARIANT|VT_BYREF); >> #my $nodes = Win32::OLE::Variant->new(VT_ARRAY|VT_VARIANT|VT_BYREF, 0); >> >> my $objChildGroups = $objGetRoot->GetChildNodeGroups($nodes, "True"); >> if (Win32::OLE-> LastError() != 0) { >> print "Error calling GetChildNodeGroups: " . Win32::OLE->LastError() . >> "\n"; >> exit 0; >> } >> print "Child Group Count: " . $objChildGroups . "\n"; >> >> print Dumper($nodes); >> >> >> foreach my $objItem (in $nodes) { >> print 'Name: ' . $objItem->{Name} . "\n"; >> } >> >> #my $nodes = Win32::OLE::Variant->new(VT_ARRAY|VT_VARIANT, 0); Returns >> ##Child Group Count: 25 >> ##$VAR1 = bless( do{\(my $o = 27197068)}, 'Win32::OLE::Variant' ); >> ##Not a HASH reference at GetChildNodeGroups.pl line 46. >> >> #my $nodes = Win32::OLE::Variant->new(VT_VARIANT|VT_BYREF); Returns >> ##Child Group Count: 25 >> ##$VAR1 = bless( do{\(my $o = 27197828)}, 'Win32::OLE::Variant' ); >> ##Not a HASH reference at GetChildNodeGroups.pl line 46. >> >> #my $nodes = Win32::OLE::Variant->new(VT_ARRAY|VT_BSTR, 0); Returns >> ##Child Group Count: 25 >> ##$VAR1 = bless( do{\(my $o = 27198308)}, 'Win32::OLE::Variant' ); >> ##Not a HASH reference at GetChildNodeGroups.pl line 46. >> >> #my $nodes = Win32::OLE::Variant->new(VT_DISPATCH|VT_BYREF); Returns >> ##Error calling GetChildNodeGroups: Win32::OLE(0.1709) error 0x80010105: >> "The server threw an exception" >> ## in METHOD/PROPERTYGET "GetChildNodeGroups" >> >> #my $nodes = Win32::OLE::Variant->new(VT_ARRAY|VT_VARIANT|VT_BYREF, 0); >> Returns >> ##Child Group Count: 25 >> ##$VAR1 = bless( do{\(my $o = 27199076)}, 'Win32::OLE::Variant' ); >> ##Not a HASH reference at GetChildNodeGroups.pl line 46. >> >> #my $nodes = Win32::OLE::Variant->new(VT_ARRAY|VT_BSTR|VT_BYREF, 0); >> Returns >> ##Child Group Count: 25 >> ##$VAR1 = bless( do{\(my $o = 27197684)}, 'Win32::OLE::Variant' ); >> ##Not a HASH reference at GetChildNodeGroups.pl line 46. >> >> #my $nodes = Win32::OLE::Variant->new(VT_VARIANT|VT_BYREF); Returns >> ##Child Group Count: 25 >> ##$VAR1 = bless( do{\(my $o = 27199620)}, 'Win32::OLE::Variant' ); >> ##Not a HASH reference at GetChildNodeGroups.pl line 46. >> >> #my $nodes = Win32::OLE::Variant->new(VT_ARRAY|VT_VARIANT|VT_BYREF, 0); >> Returns >> ##Child Group Count: 25 >> ##$VAR1 = bless( do{\(my $o = 27199524)}, 'Win32::OLE::Variant' ); >> ##Not a HASH reference at GetChildNodeGroups.pl line 46. >> >> Does any of this, make any sense to you guys? >> >> /Michael >> > > > so, it looks like your Dumper statement is indicating a valid object in > most cases. I think the problem on your loop is that you are using the > 'in' adapter, which requires the object to be IEnumerable. A variant > array is not enumerable (I believe) - so just try treating it like an > array, maybe something like this > > foreach my $objItem (@$nodes) { > print 'Name: ' . $objItem->{Name} . "\n"; > } > > > -Mike
Well it just changes the error to: Child Group Count: 25 $VAR1 = bless( do{\(my $o = 27200092)}, 'Win32::OLE::Variant' ); Not an ARRAY reference at GetChildNodeGroups.pl line 46. Damn this is complicated :-S /Michael _______________________________________________ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs