none
Problems using WMI to Hyper-V on Windows 2016 Server

    Question

  • I have a C# program that uses WMI to create and start virtual machines in Hyper-V. 
    This program has been working against Windows 2012 and 2012R2 Hyper-V servers for several years.

    When I try to run this program on a Win2016 VM communicating with Hyper-V on a Windows 2016 server, I am seeing multiple failures.

    I can create the VM via WMI and I see it in Hyper-V Manager. My program performs a ManagementObjectSearcher query to return the Msvm_ComputerSystem object. It then gets the VM's Msvm_VirtualSystemSettingData settings.
    Then it gets the Msvm_ResourceAllocationSettingData settings. 

    Running the code below in a Windows 2012 environment, I could always find a resource of the sub type
    "Microsoft:Hyper-V:Serial Port". This is not returned using the same calls in a Windows 2016 environment.

                resourceCollection = vmSettings.GetRelated
                (
                    "Msvm_ResourceAllocationSettingData",
                    "Msvm_VirtualSystemSettingDataComponent",
                    null,
                    null,
                    "PartComponent",
                    "GroupComponent",
                    false,
                    null
                );

    Looking at Event logs in the Hyper-V server I see the following error after the above query:

        Operation = Start |WbemServices::ExecNotificationQuery - root\virtualization\V2 : SELECT * FROM _InstanceModificationEvent WITIN2 WHERE TargetInstance ISA 'Msvm_ConcreteJob'; ResultCode = 0x80041032

    I see the same event when I try to start the VM and wait for it to start. I query the JobState waiting for it to get in to the Completed state. Instead it is in the Exception state. The VM does appear to start, according to Hyper-V Manager

                

    • Edited by PeterDon Monday, February 13, 2017 7:01 PM
    Monday, February 13, 2017 1:50 PM

Answers

  • It doesn't seem like a programming issue to me. It seems like a problem, or at least a change, in the WMI provider. That subtype appears to be gone, or at least invisible, to 2016.

    This is a VM running on a 2012 R2 system:

    Serial Port on 2012 R2

    This is a replica of the same VM on a 2016 system:

    No Serial Port on 2016

    I then did a .GetRelated on the item with a subtype of ...Serial Controller and it found two objects with a class name of "Msvm_SerialPortSettingData". Searches for that class find hits on OpenStack, but nothing in the official Microsoft documentation.

    Anyway, you'll need to modify your code to work with 2016. Looks like an undocumented change to the Hyper-V WMI provider.


    Eric Siron
    Altaro Hyper-V Blog
    I am an independent contributor, not an Altaro employee. I accept all responsibility for the content of my posts. You accept all responsibility for any actions that you take based on the content of my posts.

    • Marked as answer by PeterDon Tuesday, February 21, 2017 2:43 PM
    Saturday, February 18, 2017 1:50 AM

All replies

  • Hi PeterDon,

    >>When I try to run this program on a Win2016 VM communicating with Hyper-V on a Windows 2016 server, I am seeing multiple failures.

    Not sure if it anything changed in 2016.

    I suppose the issue is related to coding. You could post in MSDN forum for better help.

    Best Regards,

    Leo


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Tuesday, February 14, 2017 2:37 AM
    Moderator
  • Thanks Leo! I thought this was the MSDN forum - what forum are you referring to?
    Friday, February 17, 2017 4:00 PM
  • msdn.microsoft.com/forums - Find an appropriate developers forum.  This is a TechNet forum dealing with general questions about Hyper-V configuration, management, and use, not programming.

    . : | : . : | : . tim

    Friday, February 17, 2017 7:58 PM
  • It doesn't seem like a programming issue to me. It seems like a problem, or at least a change, in the WMI provider. That subtype appears to be gone, or at least invisible, to 2016.

    This is a VM running on a 2012 R2 system:

    Serial Port on 2012 R2

    This is a replica of the same VM on a 2016 system:

    No Serial Port on 2016

    I then did a .GetRelated on the item with a subtype of ...Serial Controller and it found two objects with a class name of "Msvm_SerialPortSettingData". Searches for that class find hits on OpenStack, but nothing in the official Microsoft documentation.

    Anyway, you'll need to modify your code to work with 2016. Looks like an undocumented change to the Hyper-V WMI provider.


    Eric Siron
    Altaro Hyper-V Blog
    I am an independent contributor, not an Altaro employee. I accept all responsibility for the content of my posts. You accept all responsibility for any actions that you take based on the content of my posts.

    • Marked as answer by PeterDon Tuesday, February 21, 2017 2:43 PM
    Saturday, February 18, 2017 1:50 AM
  • Thanks Eric - I see the same thing on my 2 Hyper-V hosts. I think that's what I needed to sort this out. I'll post a response here once I find a workable solution (when I get back to working on this problem).
    Tuesday, February 21, 2017 2:42 PM
  • Just to close the loop on this issue, I can now process the serial ports using the code below. If the resourceCollection does not contain a serial port, I use the serialController to find them.

        ManagementObjectCollection resourceCollection = vmSettings.GetRelated
        (
            "Msvm_ResourceAllocationSettingData",
            "Msvm_VirtualSystemSettingDataComponent",
            null,
            null,
            "PartComponent",
            "GroupComponent",
            false,
            null
        );
        foreach (ManagementObject resource in resourceCollection)
        {
            if (resourceCollection == null)
            object resourceSubType = resource["ResourceSubType"];
            string subType = resourceSubType.ToString();
            if (subType.Equals(ResourceSubType.SerialController))
            {
                 serialController = resource;
                ManagementObjectCollection serialControllerCollection = serialController.GetRelated("Msvm_SerialPortSettingData");
                if (serialControllerCollection != null)
                {
                    foreach (ManagementObject serialPort in serialControllerCollection)
                    {
    		    // Process each serial port
    		}
    	    }
    	}
        }
    

    Thursday, February 23, 2017 2:29 PM
  • Nicely done.

    Eric Siron
    Altaro Hyper-V Blog
    I am an independent contributor, not an Altaro employee. I accept all responsibility for the content of my posts. You accept all responsibility for any actions that you take based on the content of my posts.

    Thursday, February 23, 2017 2:35 PM