none
C++ code to get VLAN ID for each VM in a Hyper-V using WMI.

    Question

  • Hi,

    I have a Hyper-V machine with 10 VMs.

    I need the VLAN ID for each VM. I do not have access to the port name to which the VM's adapter is connected.

    Get-WmiObject-ClassMsvm_VLANEndpointSettingData -Namespace"root\virtualization" -ComputerName"."|format-table-propertyAccessVLAN -Autosize

    Running the above command in power shell is not returning the VLAN IDs, it says ivalid class name.

    What is the right namespace to be used for the class"Msvm_VLANEndpointSettingData"?

    ("root\virtualization" and "root\virtualization\v2" didn't work)

    I need the code in c++

    Thanks.



    • Edited by Amulya23 Tuesday, May 2, 2017 3:46 PM
    Tuesday, May 2, 2017 12:54 PM

All replies

  • Hi Sir,

    Please use this article to check the vlan setting :

    gwmi -Namespace root\virtualization\v2 -query "select * from Msvm_ethernetswitchportvlansettingdata"
     

    Please check the value of "instanceid" :

    Based on my test , the first part is VM ID .

    This is more related to development , to get further assistance I'd suggest you post it into developer's forum:

    https://social.msdn.microsoft.com/Forums/en-us/home

    Hope it is helpful to you .

    Best Regards,

    Elton


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

    Wednesday, May 3, 2017 9:34 AM
    Moderator