Ruby & WMI (win32ole)

Discussion in 'Ruby' started by Nicholas Calvert, Jun 17, 2008.

  1. Hi guys,

    First off, hello :) New to the community, looks very helpful and active
    indeed...

    As i say, I am new to Ruby and am trying to port some WMI Powershell
    code over – I am not having much luck... My goal is to automate Hyper-V
    on Windows 2008, as an example at a very simple level in powershell I
    can do:

    ## Define variable for getting VSMS class
    $VSMS = get-wmiobject MSVM_VirtualSystemManagementService -namespace
    "root\virtualization"
    ## Then call a method on that class like this. Definevirtualsystem is
    the method in question, I call it with no parameters.
    $VSMS.definevirtualsystem()

    I have tried two libarys in Ruby, win32ole and ruby-wmi. The synatx for
    ruby-wmi confused me the most, so can only post a (kind of) working
    example with win32ole:

    require 'win32ole'
    wmi =
    WIN32OLE.connect("winmgmts:\\\\localhost\\root\\virtualization:Msvm_VirtualSystemManagementService")
    wmi.ExecMethod(DefineVirtualSystem())

    ... this gives me the following error:
    test.rb:4: undefined method `DefineVirtualSystem' for main:Object
    (NoMethodError)

    Also one of the tricks with WMI is to get the XML output of a class,
    change the settings and squirt it back.

    Using the previous example, i could do:

    $VSMS.psbase.gettext(1)

    ...to give myself the raw XML. Is there an easy way to do this in Ruby?

    Any pointers would be greatly appreciated.

    Cheers,

    Nick
    --
    Posted via http://www.ruby-forum.com/.
    Nicholas Calvert, Jun 17, 2008
    #1
    1. Advertising

  2. Hello,
    Nicholas Calvert wrote:
    > I have tried two libarys in Ruby, win32ole and ruby-wmi. The synatx for
    > ruby-wmi confused me the most, so can only post a (kind of) working
    > example with win32ole:
    >
    > require 'win32ole'
    > wmi =
    > WIN32OLE.connect("winmgmts:\\\\localhost\\root\\virtualization:Msvm_VirtualSystemManagementService")
    > wmi.ExecMethod(DefineVirtualSystem())


    I have not used Powershell, so I'm not sure, but
    How about the following script?
    wmi.ExecMethod('DefineVirtualSystem')

    Regards,
    Masaki Suketa
    Masaki Suketa, Jun 18, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. yonatan
    Replies:
    0
    Views:
    117
    yonatan
    Jan 6, 2004
  2. Daniel Berger

    Segfault with win32ole, WMI and structs

    Daniel Berger, May 23, 2004, in forum: Ruby
    Replies:
    4
    Views:
    146
    Jos Backus
    May 24, 2004
  3. Daniel Berger

    Using Win32OLE, WMI and ExecMethod

    Daniel Berger, Jun 3, 2004, in forum: Ruby
    Replies:
    1
    Views:
    182
    Daniel Berger
    Jun 4, 2004
  4. Masaki Suketa
    Replies:
    4
    Views:
    370
    Dave Burt
    Mar 27, 2006
  5. Spike

    WMI and WIN32OLE issues

    Spike, Oct 26, 2006, in forum: Ruby
    Replies:
    0
    Views:
    85
    Spike
    Oct 26, 2006
Loading...

Share This Page