Wednesday, March 12, 2014

VMware Set IOPS Limit, Shares, Shares level for all virtual machines on a datastore

If you want to adjust the disk IOPS, shares, or shares level for all VMs on a datastore, here is a handy PowerCLI script to do this.

Adjust the param mandatory setting to true/false if you want to be prompted.


Param(  
 [parameter(Mandatory=$true, HelpMessage="VMware vCenter IP address")]  
 [string]$ViCenterIp,  
 [parameter(Mandatory=$true, HelpMessage="datastore")]  
 [string]$datastore,  
 [parameter(Mandatory=$false, HelpMessage="Number of Disk Shares")]  
 [int]$NumDiskShares,  
 [parameter(Mandatory=$false, HelpMessage="Disk Share Level")]  
 [ValidateSet("low","normal","high","custom")]  
 [string]$DiskSharesLevel,  
 [parameter(Mandatory=$true, HelpMessage="Disk Limit IO/s")]  
 [int]$DiskLimitIOPerSecond  
 )  
 Connect-VIServer -Server $ViCenterIp   
 #–Credentials (Get-Credential)  
 # You need to change this first cmdlet to get datastore folder instead (I believe that the syntax is Get-DatastoreFolder)  
 $VMList = Get-VM -datastore $datastore  
 $newConfiguration = ""  
 if($NumDiskShares){  
  $newConfiguration += " -NumDiskShares " + $NumDiskShares  
 }  
 if($DiskSharesLevel){  
  $newConfiguration += " -DiskSharesLevel " + $DiskSharesLevel  
 }  
 if($DiskLimitIOPerSecond){  
  $newConfiguration += " -DiskLimitIOPerSecond " + $DiskLimitIOPerSecond  
 }  
 foreach ($VM in $VMList) {  
  $VMName = $VM.Name  
  ###   
  try{  
   Invoke-Expression -Command ("Set-VMResourceConfiguration -Configuration (Get-VmResourceConfiguration -VM '$VMName') -Disk (Get-HardDisk -VM '$VMName') $newConfiguration")  
   ### Uncomment below for logging to the screen  
   ###Write-Host "Successfully applied the resource parameters to the Virtual Machine: $VMName"  
  } catch {  
 $msg = $_.Exception.Message  
 throw $msg  
   }   
 }  

This will iterate through each VM and set the IOPS limit, shares, shares level.


No comments:

Post a Comment

Featured Post

Remove 3D Objects and other annoying folders on Windows 10

 Microsoft just keeps adding more crap to clutter up the navigation in Windows 10.  Seriously, who needs a 3D Objects folder?  The tiny perc...