Implementing Hyper-V remote Management through WMI (i)

Source: Internet
Author: User

Recently, the company needs to do the remote management of Hyper-V, extend the management of Hyper V on the basis of existing products, realize remote switch, open virtual machine remotely, other content can see the description of Hyper-V in MSDN and the related instance code, WMI Operation Hyper Tool class, Hyper-V

Ok, nonsense don't say, the text begins ...

1. Install the Hyper-V virtual machine, which is installed in version 2012 and create two virtual machines after installation

2. Access to a lot of data, the common way is to use WMI to interact with the hyper, through the tool to scan the Hyper WMI node

Found a total of 22 direct classes

Each class is viewed one at a to find only 3 large classes that can interact

Call one by one:

1[Dynamic: ToInstance, provider ("Vmmswmiinstanceandmethodprovider"), Locale (1033)]2 classMsvm_computersystem:cim_computersystem3 {4[Read, ArrayType ("Indexed")] [uint16 assignednumanodelist[];5[Read, Units ("MilliSeconds")] UInt64 ontimeinmilliseconds;6 [read] UInt32 ProcessID;7 [Read] datetime timeoflastconfigurationchange;8[Implemented, valuemap{"0","4096","32768","32769","32770","32771","32772","32773","32774","32775","32776","32777","32778"}, Bypass_getobject, modelcorrespondence{"cim_enabledlogicalelement.requestedstate"}] UInt32 Requeststatechange ([In, valuemap{"2","3","4","5","6","7","8","9","Ten"," One"," A","..","32768..65535"}, modelcorrespondence{"cim_enabledlogicalelement.requestedstate"}] UInt16 requestedstate, [out] Cim_concretejobrefJob, [In, Subtype ("Interval"): toinstance ToSubClass] datetime timeoutperiod);9};

which

"0", "4096", "32768", "32769", "32770", "32771", "32772", "32773", "32774", "32775", "32776", "32777", "32778"

"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "...", "32768..65535"

These numbers represent the various states of a virtual machine instance, such as running, shutting down, shutting down, and so on. Such as:


0 Unknown

2 Running

3 Off

32768 Paused
32769 Suspended
32770    starting        
    32771    snapshotting   
    32773    saving         
    Span style= "color: #808080;" >32774    stopping      
     32776    pausing         
    32777    resuming   


The class that holds the virtual machine data is Msvm_computersystem, and by calling Msvm_computersystem you can get the virtual machine information under the remote hyper, which contains a description of the host:

instance of msvm_computersystem{assignednumanodelist=NULL; Caption="Host computer Systems"; CreationClassName="Msvm_computersystem"; Dedicated=NULL; Description="Microsoft host computer Systems"; ElementName="Hyper-V"; Enableddefault=2; EnabledState=2; Healthstate=5; Identifyingdescriptions=NULL; InstallDate=NULL; Name="Hyper-V"; NameFormat=NULL; Ontimeinmilliseconds=NULL; Operationalstatus= {2}; Otherdedicateddescriptions=NULL; Otherenabledstate=NULL; OtherIdentifyingInfo=NULL; PowerManagementCapabilities=NULL; Primaryownercontact=NULL; Primaryownername=NULL; ProcessID=NULL; RequestedState= A; Resetcapability=1; Roles=NULL; Status="OK"; Statusdescriptions= {"Determine"}; Timeoflastconfigurationchange=NULL; Timeoflaststatechange=NULL;};

Description of the virtual machine:

instance of msvm_computersystem{assignednumanodelist= {0}; Caption="Virtual Machines"; CreationClassName="Msvm_computersystem"; Dedicated=NULL; Description="Microsoft Virtual Machine"; ElementName="windows2012"; Enableddefault=2; EnabledState=2; Healthstate=5; Identifyingdescriptions=NULL; InstallDate="20160719031827.000000-000"; Name="F6f52fd7-42b6-4c2d-badc-c61f9b5ffd21"; NameFormat=NULL; Ontimeinmilliseconds="9193908"; Operationalstatus= {2}; Otherdedicateddescriptions=NULL; Otherenabledstate=NULL; OtherIdentifyingInfo=NULL; PowerManagementCapabilities=NULL; Primaryownercontact=NULL; Primaryownername=NULL; ProcessID=4064; RequestedState= A; Resetcapability=1; Roles=NULL; Status="OK"; Statusdescriptions= {"normal Operation"}; Timeoflastconfigurationchange="20160719084459.532773-000"; Timeoflaststatechange="20160719084459.000000-000";};
View Code

instance of msvm_computersystem{assignednumanodelist= {}; Caption="Virtual Machines"; CreationClassName="Msvm_computersystem"; Dedicated=NULL; Description="Microsoft Virtual Machine"; ElementName="win2008"; Enableddefault=2; EnabledState=3; Healthstate=5; Identifyingdescriptions=NULL; InstallDate="20160719081005.000000-000"; Name="7a591782-9eec-46cd-ae43-afe4efd23390"; NameFormat=NULL; Ontimeinmilliseconds="0"; Operationalstatus= {2}; Otherdedicateddescriptions=NULL; Otherenabledstate=NULL; OtherIdentifyingInfo=NULL; PowerManagementCapabilities=NULL; Primaryownercontact=NULL; Primaryownername=NULL; ProcessID=NULL; RequestedState= A; Resetcapability=1; Roles=NULL; Status="OK"; Statusdescriptions= {"normal Operation"}; Timeoflastconfigurationchange="20160719104106.665157-000"; Timeoflaststatechange="20160719104106.000000-000";};
View Code

Virtual machine information gets finished!

Implementing Hyper-V remote Management through WMI (i)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.