Revered Monks ..
I'm trying to convert some clunky, but functional VB code to perl, but running into trouble with the perl version (Snippet):
use strict; use warnings; use Win32::OLE qw(in with valof) ; use constant RUNNING=>5; my @VMList; #Connect to Virtual Server my $VirtualServer = Win32::OLE->new('VirtualServer.Application' ) or die "Oops, cannot Connect to Host Virtual server\n" & Win32 +::OLE->LastError(); print "Name: " . valof $VirtualServer->Name() . "\n"; foreach my $vm (in $VirtualServer->VirtualMachines) { print " Name: " . valof $vm->Name . " State: " . valof $vm->Sta +te . "\n"; }
The error I get is:
Win32::OLE(0.1403) error 0x80070542: "Either a required impersonation +level was not provided, or the provided impersonation level is invalid" in METHOD/PROPERTYGET "Name" at d:\Scripts\BackupVM.pl line 14 Use of uninitialized value in concatenation (.) or string at d:\Script +s\BackupVM .pl line 14. Name: Win32::OLE(0.1403) error 0x80070542: "Either a required impersonation +level was not provided, or the provided impersonation level is invalid" in METHOD/PROPERTYGET "VirtualMachines" at d:\Scripts\BackupVM.pl +line 16 Can't call method "Name" on an undefined value at d:\Scripts\BackupVM. +pl line 18 .
(First Line number corresponds to the first (print "Name...)) statement.

I know there is no security or user rights problem because
a) The equivalent VB code runs fine
b) I'm running as the godly domain admin

Here is the relevent snippet of (ugh!) VB:

Option Explicit On Error Resume Next Dim op,who,I,virtualServer Dim vmachine(50) Dim objvmColl,objVM Const RUNNING=5 Const ForReading=1,ForWriting=2 'Connect to Virtual Server Set virtualServer = CreateObject("VirtualServer.Application") op=WScript.Arguments(0) Who=WScript.Arguments(1) I=0 if op = "list" then Wscript.Echo "Name: " & virtualServer.Name Set objVMColl = virtualServer.VirtualMachines If objVMColl.Count = 0 Then Wscript.Echo " Virtual machines: [none]" Else Wscript.Echo "Virtual machines: " & objVMColl.Count For Each objVM in objVMColl VirtualMachineInfo(objVM) Wscript.Echo " Name: " & objVM.Name & " State: " & obj +VM.State Next End If end if wscript.echo I & " machines are RUNNING: " Redim preserve vmachine(I) Dim vm, fso, MyFile
Please help with insights ... TIA.

     "There are only two truly infinite things. The universe and stupidity, and I'm not too sure about the universe"- Albert Einstein


In reply to Win32 VirtualServer Automation prob: Perl Vs. VB by NetWallah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.