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