Hi, I've a lot of test vm's which are bullying our central storage. Now I've found the perfect script from Luc D which imports data from a csv file and then limits the disks. Unfortunately I...
See more...
Hi, I've a lot of test vm's which are bullying our central storage. Now I've found the perfect script from Luc D which imports data from a csv file and then limits the disks. Unfortunately I get red errors when I fire it up: Get-VM : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again. At H:\PowerCLI\VmIOPSLimit.ps1:13 char:22 + $vm = Get-VM -Name $group.Name + ~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [Get-VM], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM You cannot call a method on a null-valued expression. At H:\PowerCLI\VmIOPSLimit.ps1:23 char:3 + $vm.ExtensionData.ReconfigVM_Task($spec) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull Can someone help me out? Here's the script from Luc D. which I found on the powercli community: foreach($group in (Import-Csv C:\vmiopslimit.csv -UseCulture | Group-Object -Property vmName)){ $vm = Get-VM -Name $group.Name $spec = New-Object VMware.Vim.VirtualMachineConfigSpec $vm.ExtensionData.Config.Hardware.Device | where {$_ -is [VMware.Vim.VirtualDisk]} | %{ $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec $dev.Operation = "edit" $dev.Device = $_ $label = $_.DeviceInfo.Label $dev.Device.StorageIOAllocation.Limit = $group.Group | where {$_.Harddisk -eq $label} | Select -ExpandProperty IOPSLimit $spec.DeviceChange += $dev } $vm.ExtensionData.ReconfigVM_Task($spec) } The CSV file should look like this "vmName","harddisk","IOPSLimit" "VM1","Hard disk 1","50" "VM1","Hard disk 2","75" "VM2","Hard disk 1","75" "VM3","Hard disk 1","35" "VM3","Hard disk 2","55" "VM3","Hard disk 3","65"