PowerCLI and VAAI : Quick and dirty script

How can you enable or disable VAAI across all the ESX hosts in a cluster through a script? This question was tossed up on the vSpecialist email list this afternoon by our fearless leader.

Having just played with this I thought I would share my quick and dirty PowerCLI code. This basically asks for your vCenter URL and then asks whether you want to disable or enable across all ESX hosts within that vCenter.

Then it goes through each one and enables/disables the settings that correspond. Simple, easy, dirty script that can be manipulating how you wish. Code below:

param(
    [parameter(Mandatory = $true)]
    [string]$vCenter
)
[reflection.assembly]::loadwithpartialname(“microsoft.visualbasic”) | Out-Null
$d = [Windows.Forms.MessageBox]::Show("Change VAAI on all hosts? (Yes = Enable, No = Disable)", "Change VAAI on all hosts?", [Windows.Forms.MessageBoxButtons]::YesNoCancel, [Windows.Forms.MessageBoxIcon]::Question)

if ($d -eq [Windows.Forms.DialogResult]::Yes) {
    Connect-VIServer $vCenter
    $esxHosts = Get-VMHost | Sort Name
    foreach($esx in $esxHosts){
        Write-Host "Enabling VAAI"
        Set-VMHostAdvancedConfiguration -VMHost $esx -Name DataMover.HardwareAcceleratedMove -Value 1 -Confirm:$false
        Set-VMHostAdvancedConfiguration -VMHost $esx -Name DataMover.HardwareAcceleratedInit -Value 1 -Confirm:$false
        Set-VMHostAdvancedConfiguration -VMHost $esx -Name VMFS3.HardwareAcceleratedLocking -Value 1 -Confirm:$false
    }
}
if ($d -eq [Windows.Forms.DialogResult]::No) {
    Connect-VIServer $vCenter
    $esxHosts = Get-VMHost | Sort Name
    foreach($esx in $esxHosts){
        Write-Host "Disabling VAAI"
        Set-VMHostAdvancedConfiguration -VMHost $esx -Name DataMover.HardwareAcceleratedMove -Value 0 -Confirm:$false
        Set-VMHostAdvancedConfiguration -VMHost $esx -Name DataMover.HardwareAcceleratedInit -Value 0 -Confirm:$false
        Set-VMHostAdvancedConfiguration -VMHost $esx -Name VMFS3.HardwareAcceleratedLocking -Value 0 -Confirm:$false
    }
}

Feel free to link to better versions in the comments.

.nick

EMC Life/Work Tools

4 Comments Leave a comment

  1. Hi Nick

    I altered it ever so slightly, using:
    foreach($esx in $esxHosts where $esx.Version -eq ‘4.1.0’)

    That way I don’t break my 3.5 and 4.0 hosts 🙂

    Andre

%d bloggers like this: