| Profiel van Dung K HoangDung's spaceWeblogNetwerk | Help |
|
|
07 februari Hyper-V WMI documentation not complete yet
I just find out that some WMI calls are not documented in the MSDN library for Hyper-V. Apparently there are three methods in MSvm_VirtualSystemManagementService to create a new virtual machine and only one of them is explained.
I know that the documentation is still in early beta phase and appreciate all effort of Microsoft for publishing it. Even with the current state of the materials, there is a lot of things you can do with WMI against Hyper-V So Enjoy! /Dung 05 februari Hyper-V WMI Examples - Part II
The Msvm_VirtualSystemManagementService ClassToday I discuss about the Msvm_VirtualSystemManagementService Class. The Msvm_VirtualSystemManagementService class represents the virtualization service running on the host system. Using this class, you can control the creation, modification, deletion, import and export of virtual systems. You can also create snapshots and apply them to virtual systems. All those operations are exposed as methods of the Msvm_VirtualSystemManagementService class. Creating snapshots of virtual systemsA snapshot is a point-in-time image of a virtual system. It can be seen as a quick way to backup a virtual machine. You can take a snapshot at any time with any guest operating system and can restore a virtual a machine at any stage. Let see some examples of WMI class to create and apply snapshots. First you connect to the virtualization service. PS C:\> $VSService = get-wmiobject –namespace root\virtualization –class Msvm_VirtualSystemManagementService Use get-member to discover all the methods exposed by this object PS C:\> $VSService | get-member | where {$_.Membertype -match 'Method'} Name MemberType Definition So you can see that it has some interesting methods! Using the lab environment I describe here, let consider the IIS-Core virtual system. PS C:\> $Core = get-wmiobject -namespace root\virtualization -class Msvm_ComputerSystem -filter " ElementName = 'IIS-CORE' " PS C:\> $VSService.CreateVirtualSystemSnapShot($Core.__PATH) The call should return 0 or 4096. If not, it means that there is an error in the call. Finding snapshots of virtual systemsOnce a snapshot is taken, its configuration is stored as an instance of the Msvm_VirtualSystemSettingData object. The Msvm_VirtualSystemSetting class is used to represent all virtualization-specific settings for a virtual system which can be either a virtual machine or a snapshot. A WMI query on this class will return settings of virtual machines and snapshots that currently exist on the host system. To distinguish snapshot from virtual machine, you should filter the query on the property called SettingType. This property can have one of the two values:
PS C:\> $VSService = get-wmiobject –namespace root\virtualization –class Msvm_VirtualSystemSettingData -filter "SettingType = 5" Now that you get a list of snapshots with their settings, how can you find the linkage between snapshots and virtual machine? As you know, a virtual machine can have zero snapshot or several snapshots taken at different points in time. A query to Msvm_VirtualSystemSettingData with a filter on SettingType returns a list of snapshots in the order they are created and they are not sorted per virtual machine! With this information, you can now find all snapshots that are associated to a virtual machine. PS C:\> get-wmiobject -namespace root\virtualization -class Msvm_VirtualSystemData -filter "SystemName=`'$($Core.Name)`' and SettingType = 5” Applying snapshots to a virtual systemYou can apply a snapshot to a virtual machine to restore the system to a state at the time the snapshot was taken. You don't need to apply snapshots in a particular order but can take any snapshot associated to this machine and restore it. PS C:\> # Let's assume that you have identified a particular snapshot using the example above and store the object in a variable PS C:\> # First you need to sop the virtual machine. PS C:\> # Then apply a snapshot From the Hyper-V Manager console, you will notice that the "restored" virtual system will be put in 'Saved' state mode. Starting it will restore the machine to its state before the snapshot was taken. SummaryThis entry provides examples of creating, finding and applying a snapshot on a virtual machine using the Hyper-V WMI classes. Until the next time.... /Dung
|
|
|