Hyper-V Automation through scripts (Processor)
October 16, 2009 | In: Hyper-V
Last time I covered automatic Hyper-V through WMI for virtual disks. Now, I want to cover how to automate the creation of processor resources. One thing you will notice is that the pattern used to create virtual disks through WMI will be very similar for creating the rest of our resources. As we figure out how to manipulate settings of virtual machine components, it becomes easier to build a complete script
# Set up variables$VHD = "f:\VHDs\win2k8.vhd" $GuestVM = "Win2k8" $Namespace = "root\virtualization" $Computer = "Hyper-V2k8" # Get instance of Msvm_VirtualSystemManagementService class$VSMSvc = Get-WmiObject -Class "Msvm_VirtualSystemManagementService" -Namespace $Namespace -ComputerName $Computer # Get instance of Msvm_ComputerSystem class$VM = Get-WmiObject -Namespace $Namespace -ComputerName $Computer -Query "Select * From Msvm_ComputerSystem Where ElementName='$GuestVM'" #Associating Msvm_VirtualSystemSettingData class with $VM$VMVSSD = Get-WmiObject -Namespace $Namespace -Query "Associators of {$VM} Where ResultClass=Msvm_VirtualSystemSettingData AssocClass=Msvm_SettingsDefineState" # Define instance of Virtual processor through an association$VMProc = (Get-WmiObject -Namespace $Namespace -Query "Associators of ($VMVSSD) Where ResultClass=Msvm_ProcessorSettingData AssocClass=Msvm_VirtualSystemSettingDataComponent" | where-object -FilterScript {$_.ResourceSubType -eq "Microsoft Processor"}) # Define Processor resource attributes# set number of processors$VMProc.VirtualQuantity = [string]1# set other attributes that are viewable in Hyper-V manager$VMProc.Reservation = [string]0$VMProc.Limit = [string]100000$VMProc.Weight = [string]100$VSMSvc.ModifyVirtualSystemResources($VM._Path, $VMProc.PSBase.GetText(1))
There you are. Adding a virtual processor through WMI using our already established pattern for defining resources. Next time I will cover adding memory resources.
3 Responses to Hyper-V Automation through scripts (Processor)
Tweets that mention Hyper-V Automation through scripts (Processor) – davidramthun.com -- Topsy.com
October 16th, 2009 at 2:15 pm
[...] This post was mentioned on Twitter by VM Digest, David Ramthun. David Ramthun said: Hyper-V Automation through scripts (Processor) http://bit.ly/2Ijc75 [...]
Hyper-V Automation through scripts (Memory) – davidramthun.com
October 19th, 2009 at 9:46 am
[...] Last time I looked at building onto our WMI automation script with processor creation. Today, I want to cover how to add memory resources into the script. Once again, I will take advantage of the existing patterns for creating this script. [...]
Hyper-V Automation through scripts (Final Script) – davidramthun.com
December 7th, 2009 at 2:59 pm
[...] so far we have created, modified, and added resources (memory, processor, disks, and network) to virtual machines. Now, we want to take that information and build a [...]