# Found 6/19/16 http://vmscribble.com/powercli/change-sdrs-vm-affinity-io-metric-space-threshold-by-cluster-script
# Add the PowerCLI snapin to PowerShell
Add-PSsnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
# thanks http://frankdenneman.nl/2012/02/21/impact-of-intra-vm-affinity-rules-on-storage-drs/
function Set-DatastoreClusterDefaultIntraVmAffinity{
param(
[CmdletBinding()]
[parameter(Position = 0, Mandatory = $true, ValueFromPipeline = $true)]
[PSObject]$DSC,
[Switch]$Enabled
)
process{
$SRMan = Get-View StorageResourceManager
if($DSC.GetType().Name -eq "string"){
$DSC = Get-DatastoreCluster -Name $DSC | Get-View
}
elseif($DSC.GetType().Name -eq "DatastoreClusterImpl"){
$DSC = Get-DatastoreCluster -Name $DSC.Name | Get-View
}
$spec = New-Object VMware.Vim.StorageDrsConfigSpec
$spec.podConfigSpec = New-Object VMware.Vim.StorageDrsPodConfigSpec
$spec.podConfigSpec.DefaultIntraVmAffinity = $Enabled
$SRMan.ConfigureStorageDrsForPod($DSC.MoRef, $spec, $true)
}
}
# Set Variables
$vCenter = Read-Host "Enter the FQDN of the vCenter"
$listofclusters = Read-Host "Enter the path to the list of storage clusters ex. c:scriptsclusters.txt"
$clusName = Get-Content -path $listofclusters
# Connect to your vCenter
Connect-VIServer $vCenter
# Default VM affinity = un-checked
Get-DatastoreCluster $clusName | Set-DatastoreClusterDefaultIntraVmAffinity
# I/O metric inclusion = un-checked / Space threshold = 75%
Get-DatastoreCluster $clusName| Set-DatastoreCluster -IOLoadBalanceEnabled $false | Set-DatastoreCluster -SpaceUtilization 75 -Confirm:$false
# Disconnect from the vCenter
Disconnect-VIServer $vCenter -Confirm:$false