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 PowerShell to modify the Resource Setting this is possible using the psbase method, but when doing this through VBScript I get the error "Invalid method Parameter(s)". The VBScript script is a narrowed down version of the total script I would like to use. Both the PowerShell and command line are running with elevated permissions.
Below the PowerShell codes which runs without any issues:
=========================================================
# One of the Virtual Machine ID
$sVMId = "92B40B3E-7178-403C-A267-29884DC779FF";
# Get the Virtual System Management Service to modify resource settings
$oVSMS = Get-WmiObject -Namespace "root\virtualization\v2" -Class Msvm_VirtualSystemManagementService;
# Generation 2 VM
$oVM = Get-WmiObject -Namespace root\virtualization\v2 -Class Msvm_ComputerSystem | Where-Object { $_.Name -eq $sVMId};
# Get the VM setting data
$oVMSet = $oVM.GetRelated() | Where-Object {$_.__CLASS -eq "Msvm_VirtualSystemSettingData"};
# Get related disk (single disk attached)
$oVMDiskImages = $oVMSet.GetRelated() | Where-Object {$_.__CLASS -eq "Msvm_StorageAllocationSettingData"};
# IOPS settings
$oVMDiskImages.IOPSLimit = 400;
$oVMDiskImages.IOPSReservation = 350;
# Get the input method object to modify settings
$oInParams = $oVSMS.GetMethodParameters("ModifyResourceSettings");
# Fill the input object with the new settings
$oInParams.ResourceSettings = $oVMDiskImages.GetText(1);
# Modify the Msvm_StorageAllocationSettingData
$oOutParams = $oVSMS.InvokeMethod("ModifyResourceSettings",$oInParams,$Null);
# Display the method return value
$oOutParams.ReturnValue;
=========================================================
Below the VBScript code which give an error when the ExecMethod_ method is used:
================================================================================
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 would like to change the settings through a VBScript as this can be imported into Operations Manager as a Script task which can be run on any Hyper-V server which has the Operations Manager Agent installed (including Hyper-V hosts within the DMZ, non VMM managed hosts, managed through a Gateway server in a non-trusted domain).
One of the things it might be that it doesn't run is that the ModifyResourceSettings method expects a CIM_ResourceAllocationSettingData class as input, but the input is Msvm_StorageAllocationSettingData. I have other VBScript examples that modifies resources,
but in these scripts the input parameter contains the same class and not a derived class.
Thanks in advance,
Dennis van den Akker
d.vandenakker@icento.nl