A couple of weeks ago VMware released the PowerCLI Extensions Fling. This gives users early access to experimental PowerCLI functionality in the form of modules.
Whilst the highlight of the release was undoubtedly Instant Clone (aka VMFork), a bunch of cmdlets appeared for configuring vFlash on hosts. Fortunately for me, I recently had cause to use them.
This week I was tasked with enabling vFlash on all nodes in a cluster, each of which had been provisioned with a 200GB SSD. With twenty hosts to do, configuring each one through the vSphere Web Client wasn’t the preferred option. Thankfully the new PowerCLI cmdlets came to the rescue.
Make sure you are running PowerCLI 6.0. You check this by running the following command in your current PowerCLI installation:
Get-VIToolkitVersion
Download the fling from VMware and unzip to a folder. Using PowerCLI, find your modules directory using:
$Env:PSModulePath
Copy the VMware.VimAutomation.Extensions folder to the modules directory. On my system, the complete path was:
C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules\
Verify the modules are in place by running the following command:
Get-Module -ListAvailable VM*
This should give you:
List the commands in the Extensions Fling:
Get-Command -Module VMware.VimAutomation.Extensions
This will show:
Fortunately for me, the SSDs I wanted to use for my vFlash resource were the second disk on each node in the cluster. Using esxcli I retrieved the canonical name for each one:
esxcli storage core device list
This made things a lot easier. Now we know the commands are there and the name of each SSD, we can create our script. The following PowerCLI script connects to each node of the cluster and adds the installed SSD as the vFlash resource. It then configures the host swap cache to 150GB:
# Variables $vc = "vc2.uk.mdb-lab.com" $cred = Get-Credential $cluster = "London Cluster" # Connect to vCenter Connect-VIServer -Server $vc -Credential $cred Import-Module VMware.VimAutomation.Extensions $myCluster = Get-Cluster $cluster ForEach ($esxi in ($myCluster | Get-VMHost)) { # Get current vFRC configuration Write-Host "Getting current vFRC configuration for" $esxi -foregroundcolor "magenta" $vFlashConfig = Get-VMHostVFlashConfiguration -VMHost $esxi # Get SSD details Write-Host "Getting" $esxi "host SSDs to be used by vFRC" -foregroundcolor "magenta" $vFlashDisk = (Get-ScsiLun -VMHost $esxi -CanonicalName mpx.vmhba1:C0:T1:L0 | Get-VMHostDisk) # Enable vFRC on selected host Write-Host "Setting vFRC configuration for" $esxi -foregroundcolor "magenta" Set-VMHostVFlashConfiguration -VFlashConfiguration $vFlashConfig -AddDevice $vFlashDisk # Set vFRC host swap cache Write-Host "Setting vFRC host swap cache for" $esxi -foregroundcolor "magenta" Set-VMHostVFlashConfiguration -VFlashConfiguration $vFlashConfig -SwapCacheReservationGB 150 } # Disconnect from vCenter Disconnect-VIServer $vc -confirm:$false
And that’s all there is to it.