Hyper-V Automation through scripts (Memory)

October 19, 2009 | In: Hyper-V

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.

# 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 IDE controller through an association$VMMEM = (Get-WmiObject -Namespace $Namespace -Query "Associators of ($VMVSSD) Where 

ResultClass=Msvm_MemorySettingData AssocClass=Msvm_VirtualSystemSettingDataComponent"

  | where-object -FilterScript {$_.ResourceSubType -eq "Microsoft Virtual Machine Memory"})

# Define memory resource attributes# set amount of memory (in megabytes)$VMMem.VirtualQuantity = [string]2048# set other attributes that are viewable in Hyper-V manager$VMMem.Reservation = [string]2048$VMMem.Limit = [string]2048

$VSMSvc.ModifyVirtualSystemResources($VM._Path, $VMMem.PSBase.GetText(1))

There you go. Memory has been defined and created for the virtual machine.  Next time, I will add a network resource via WMI.


related post

    • Share/Bookmark

    2 Responses to Hyper-V Automation through scripts (Memory)

    Avatar

    Hyper-V Automation through scripts (Network) – davidramthun.com

    October 22nd, 2009 at 5:01 pm

    [...] Last time I looked at scripting memory resource creating.  Today, I want to look at the final individual component, network resources.  These network resources are virtual network interfaces that are connected to a virtual switch.  A virtual network interface can be connected to a virtual machine, but will not become active until it is attached to a virtual switch. [...]

    Avatar

    Hyper-V Automation through scripts (Final Script) – davidramthun.com

    October 23rd, 2009 at 9:21 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 [...]

    Comment Form

    Leave a comment or send a note
    1. (required)
    2. (valid email required)
    3. (required)
    4. Send
    Visitor Verification
     

    cforms contact form by delicious:days

    User:
    Password:

    | Register | Lost password?