I would like to modify the IOPS limit of vhdx files for a VM running on Windows Server 2012 R2. According to "Storage Quality of Service for Hyper-V" (http://technet.microsoft.com/en-us/library/dn282281.aspx) it is possible to do this through the WMI interface.
When using the below code it gives a Invalid method Parameter(s) when running the ExecMethod_ method.
Option Explicit Const sVMId = "92B40B3E-7178-403C-A267-29884DC779FF" ' Virtual Machine Dim oLoc, oVMMs, oVSMS, oVM, oVMSet, oVMCtrls, oVMDisk, oInParams, oOutParams Set oLoc = CreateObject ("WBemScripting.SWBemLocator") Set oVMMs = oLoc.ConnectServer (".", "root\virtualization\v2") Set oVSMS = oVMMS.Get ("Msvm_VirtualSystemManagementService") Set oVM = oVMMs.ExecQuery ("select * from Msvm_ComputerSystem where Name = '" & sVMId & "'").ItemIndex (0) Set oVMSet = oVMMs.ExecQuery ("ASSOCIATORS OF {" & oVM.Path_.RelPath & "} WHERE ResultClass = Msvm_VirtualSystemSettingData").ItemIndex (0) ' Get the Msvm_ResourceAllocationSettingData and loop through to find the single SCSI controller Set oVMDisk = oVMMs.ExecQuery ("ASSOCIATORS OF {" & oVMSet.Path_.RelPath & "} WHERE ResultClass = Msvm_StorageAllocationSettingData").ItemIndex (0) oVMDisk.IOPSLimit = 450 oVMDisk.IOPSReservation = 400 ' Create input parameter object Set oInParams = oVSMS.Methods_("ModifyResourceSettings").InParameters.SpawnInstance_() ' Fill the input object with the new settings (array is required, otherwise type mismatch) oInParams.ResourceSettings = Array (oVMDisk.GetText_(1)) ' Modify the Msvm_StorageAllocationSettingData, below: Invalid method Parameter(s) Set oOutParams = oVSMS.ExecMethod_("ModifyResourceSettings", oInParams) ' Display the method return value WScript.Echo oOutParams.ReturnValue Set oInParams = Nothing Set oVMDisk = Nothing Set oVMSet = Nothing Set oVM = Nothing Set oVSMS = Nothing Set oVMMs = Nothing Set oLoc = Nothing
I have another script that I use to modify IP adresses of an HyperV guest which uses the following code (I would guess the code to modify Resource Settings should be ok).
Set oInParams = oVSMS.Methods_("SetGuestNetworkAdapterConfiguration").InParameters.SpawnInstance_() oInParams.ComputerSystem = oVM.Path_.Path oInParams.NetworkConfiguration = Array (oItem.GetText_(1)) ' oItem is a Msvm_GuestNetworkAdapterConfiguration class Set oOutParams = oVSMS.ExecMethod_("SetGuestNetworkAdapterConfiguration", oInParams)
The main difference between these is that the Msvm_StorageAllocationSettingData is a derived class of the expected CIM_ResourceAllocationSettingData class and for the SetGuestNetworkAdapterConfiguration method the expected class Msvm_GuestNetworkAdapterConfiguration is used.
I would like to know what should be changed to the VBScript to use the method ModifyResourceSettings for modification of the Msvm_StorageAllocationSettingData object.
Thanks in advance,
Dennis van den Akker
d.vandenakker@icento.nl