Showing posts with label virtual processor. Show all posts
Showing posts with label virtual processor. Show all posts

Friday, October 16, 2009

Hyper-V Automation through scripts (Processor)

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.