| Profiel van Dung K HoangDung's spaceWeblogNetwerk | Help |
|
|
16 juni TechNet Webcast on Hyper-V WMI
I will deliver a TechNet webcast next month to talk on Hyper-V WMI and PowerShell Here is the link for register Webcast Name: Managing Hyper-V Virtual Machines with WMI and Windows PowerShell (Level 300) Date: 7/2/2008 08:00 AM PST – 09:00 AM PST
See you there! /Dung 13 juni Hyper-V WMI Examples – Part XIX
Virtual Machine creation – Revisiting the topic againSince I start the blog, I have seen many questions on how to create a new virtual machine and define resources such as memory, NICs at creation time. I must admit that the same question is in the back of my mind since a while and after looking at this blog entry of the Virtual PC guy, http://blogs.msdn.com/virtual_pc_guy/archive/2008/05/28/scripting-vm-creation-with-hyper-v.aspx, I decide to re-visit the topic and cover multiple scenarios here. In order to create a new virtual machine in Hyper-V, you must use the method DefineVirtualSystem of the Msvm_VirtualSystemManagementService object. This method accepts 3 parameters:
It is quite intimidating for those who just want to create a virtual machine with resources pre-defined for this VM, but if you read this blog since the beginning, you will see that it’s quite simple :=). Scenario 1: Creating a blank VMI notice that if you call this method without any parameter, it will create a blank virtual machine! ( although the documentation mentions that the 1st parameter is mandatory). So in its simplest form, creating a VM can be achieved with 3 lines of scripts: Script$Server = “localhost” $VM_Service.DefineVirtualSystem() The virtual machine will be created and displayed as “New Virtual Machine”
Scenario 2: Creating a VM with a pre-defined nameThe blog post mentioned above shows how to create a new VM and specify a new display name at time of creation. I will not reproduce the code here but basically you create a new instance of the class MSvm_VirtualSystemGlobalSettingData, change the display name and then call DefineVirtualSystem.
Scenario 3: Creating a VM and specifying resourcesIn this scenario, I want to create a virtual machine with two NIC cards. For this, I will be leveraging some scripts developed/ shown in Hyper-V WMI Examples - Part XIV for creating network adapters. The first NIC will have static MAc Address while the second one will use dynamic MAC address. Script$Server = “localhost” $VMGlobalSettingClass = [WMIClass]”\\Localhost\root\virtualization:Msvm_VirtualSystemGlobalSettingData" $NewGS = $VMGlobalSettingClass.psbase.CreateInstance() ## Now Create 2 NICs $GUID1 = [GUID]::NewGUID().ToString() $DefaultNIC = gwmi -namespace root/virtualization Msvm_SyntheticEthernetPortSettingData | where {$_.InstanceID -like "*Default*"} $StaticNIC = DefaultNIC.psbase.Clone() $DynamicNIC = DefaultNIC.psbase.Clone() ## Build an array of resources as required by DefineVirtualSystem $RASD = @() $RASD += $StaticNIC.psbase.gettext(1) ## Finally call DefineVirtualSystem $VM_Service.DefineVirtualSystem($NewGS.__PATH, $RASD) Et Voilà! Now that you understand the process, you can leverage my other examples to add DVD drive, new hard disks when creating virtual machines. I will leave it to you as homework for this weekend!
Enjoy! /Dung 11 juni Hyper-V WMI Examples – Part XVIII
How to find list of VMs connected to a given switch?In MS Virtual Server 2005, when looking at a virtual network, you can easily find a list of VMs that are attached to this network. Well, there is no easy way to find it within Hyper-V unless …. Andy Schneider has asked the same question on getting a list of connected VMs per switch. So here is the result. Enjoy! Steps
NoteThe script finds all virtual machines that are attached to a given virtual machines. Those virtual machines must be running ,.ie. powered on to be listed by the script. Script$ListofVMs = gwmi -namespace root\virtualization Msvm_ComputerSystem -filter "ElementName <> Name" foreach ($Switch in $ListofSwitches) foreach ($Port in $PortsOnSwitch) Enjoy! /Dung 10 juni Hyper-V WMI Explained - Part II
Management ServicesIn Hyper-V there are 3 services that govern all management activities of the virtual environment:
The figure below maps various action items shown in the Hyper-V Manager console to the three services described above Until the next time! Enjoy, /Dung Hyper-V WMI Explained - Part I
IntroductionI received many requests to explain some PowerShell examples on Hyper-V WMI so now it's great time to start a new series to dive in more detailed explanation about Hyper-V WMI. First let me say that your support through e-mail in the last few months are exceptional and I'd like to thank all the folks who send comments/suggestions to enhance the examples ( except for some scams in the blog!). Second let me write down a short disclaimer before going into technical details.
DisclaimerAll the information provided here are based on my own understanding of Hyper-V WMI during many hours of trials and tests. I use the two documents to learn about Hyper-V WMI:
In addition, I extensively use PowerShell and especially the get-member cmdlet to discover methods and properties of WMI object classes. This is a must if you want to write scripts or code against Hyper-V WMI. There certainly are other tools to browse WMI objects and I find Powershell quite handy for me. Finally, explanations provided are my interpretation of the documentation and based on my own testing. As such all the errors are also mine too! Now let's start then! /Dung 06 juni Hyper-V WMI Examples - Part XVII
Removing virtual machines from Hyper-VThe following script is used to remove virtual machines from the Hyper-V console. ## Connect to the Virtual Management Service
Enjoy! /Dung 03 juni Hyper-V WMI Examples - Part XVI
Changing the Boot order of a VMSometimes you may want to change the Boot order of a VM, for instance, to PXE boot a VM, to boot from a CD/DVD, or to simply fix the order to always start booting from the disk. You use the Msvm_VirtualSystemSettingData class to change the boot order setting f a VM. Objects of this class represents virtual "motherboard"" of a virtual machine and store virtualization-specific settings of a VM.
Script$VMName = "My Virtual Machine" $VM_Service = get-wmiobject –namespace root\virtualization Msvm_VirtualSystemManagementService # Step 1 $VM = get-wmiobject –namespace \root\virtualization Msvm_ComputerSystem | where {$_.ElementName -like $VMName ) # Step 2 - Get its "motherboard" $MB = get-wmiobject –namespace \root\virtualization Msvm_VirtualSystemSettingData | where {$_.ElementName -like $VMName ) # Step 3 - Change the Boot Order # Values are 0: Boot from floppy – 1: Boot from CD – 2: Boot from disk – 3:PXE Boot $MB.BootOrder = 3,1,2,0 # Step 4 $VM_Service.ModifyVirtualSystem($VM.__PATH, $MB.psbase.GetText(1))
Et Voilà! Enjoy! /Dung |
|
|