locked
WMI as a Hyper-V negotiator RRS feed

  • Question

  • Please assist if we can manage Hyper-V from WMI?  We are trying to create and manage VMs from ruby script using WMI. The idea really is to develop a Hyper-V adapter for a virtual machines wrapper called Vagrant (http://vagrantup.com/), so systems with Hyper-V (win8 and 8.1) don't have VirtualBox or VMware dependency. Here is the discussion: https://github.com/mitchellh/vagrant/issues/1244

    For example for the initialization step we need to find whether or not service exists. In our Ruby script, we are using WMI to identify if machine has SLAT support:

    require 'win32ole'
     
    wmi = WIN32OLE.connect('winmgmts://')
    result = wmi.ExecQuery('select SecondLevelAddressTranslationExtensions from Win32_Processor').to_enum.first
     
    if result && result.SecondLevelAddressTranslationExtensions
      puts 'SLAT Available'
    else
      puts 'SLAT Not Available'
    end
    

    But in order to know for sure if client has capable hardware AND OS with Hyper-V server installed, SLAT is not enough:

    Function TestServiceExists ($ServiceName) 
    {
        if (Get-Service $ServiceName -ErrorAction SilentlyContinue)
        {
            return 1;
        }
        return 0;
    }
    
    TestServiceExists("Hyper-V Virtual Machine Management");
    

    From Ruby script, I compressed it like:

    `powershell Function TestServiceExists ($ServiceName)  { if (Get-Service $ServiceName -ErrorAction SilentlyContinue) { return 1;} return 0; }; TestServiceExists('Hyper-V Virtual Machine Management');`.to_i

    (anything wrapped in back tick will be interpreted as system command, to_i is to convert the result to integer)

    Is there a way to carry out detect, create, start, stop, suspend, restart (and other listed here http://technet.microsoft.com/en-us/library/hh831705.aspx) operations using WMI?

    Any help/contribution would be much appreciated.

    • Moved by Bill_Stewart Thursday, January 2, 2014 8:28 PM Abandoned
    Wednesday, October 30, 2013 4:07 PM

All replies

  • Hi The Deeds, I am not sure about this requirement if you need to explore WMI - Please use this tool which may help you in many ways

    Sapien WMI Explorer


    Regards Chen V [MCTS SharePoint 2010]

    Tuesday, November 12, 2013 7:18 PM