PowerCLI Script to change the DRS Slider

So, I have a cluster of hosts that makes up our QA Environment.  As with most QA environments, it’s tight on resources and very over-subscribed.  On a regular basis, I have to move our DRS Slider to be more aggressive, RUN DRS to refresh recommendations, and then move the slider back.  This allows DRS to rebalance the cluster.  Today, I decided to script it.

I made use of a script that @lucd22 posted (http://vmw.re/1EQCDkn) to change the DRS Migration Threshold (slider value).

Here is the script:
—————————————————————————–

# Set Variables
$clusName = CLUSTER_NAME
$vCenter = VCENTER_NAME

# Connect to your vCenter
Connect-VIServer $vCenter

# Change DRS Slider to Most Agressive
# Choose the value of the slider, 1 being most agressive, and 5 being most conservative
$rate = 1

write-host "Changing DRS Migration Threshold to most agressive"

$clus = Get-Cluster -Name $clusName | Get-View

$clusSpec = New-Object VMware.Vim.ClusterConfigSpecEx
$clusSpec.drsConfig = New-Object VMware.Vim.ClusterDrsConfigInfo
$clusSPec.drsConfig.vmotionRate = $rate
$clus.ReconfigureComputeResource_Task($clusSpec, $true)

# Run DRS to get new recommendations and apply them

write-host "Refreshing DRS Recommendations"
Get-DrsRecommendation -Cluster $clusName -Refresh

# Change DRS Slider back to normal

write-host "Changing DRS Migration Threshold back to Normal"

$rate = 2

$clus = Get-Cluster -Name $clusName | Get-View

$clusSpec = New-Object VMware.Vim.ClusterConfigSpecEx
$clusSpec.drsConfig = New-Object VMware.Vim.ClusterDrsConfigInfo
$clusSPec.drsConfig.vmotionRate = $rate
$clus.ReconfigureComputeResource_Task($clusSpec, $true)

– Ben Liebowitz
Twitter:  @ben_liebowitz

Share This:

2 thoughts on “PowerCLI Script to change the DRS Slider

  1. I adapted your script to use a csv file as import to make the change on multiple clusters. The csv file has a single column with a header named Cluster. . .hence the $_.Cluster on line 6.

    # Change DRS Migration Threshold
    # Choose the value of the slider, 1 being most agressive, and 5 being most conservative
    $rate = 5

    Import-CSV “C:\temp\Change Cluster DRS level\clusters.csv” | ForEach-Object {
    $clus = Get-Cluster -Name $_.Cluster | Get-View

    $clusSpec = New-Object VMware.Vim.ClusterConfigSpecEx
    $clusSpec.drsConfig = New-Object VMware.Vim.ClusterDrsConfigInfo
    $clusSPec.drsConfig.vmotionRate = $rate
    $clus.ReconfigureComputeResource_Task($clusSpec, $true)
    }

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.