# encoding: ascii
# api: powershell
# title: ESXi scratch location
# description: Update custom scratch location ESXi 5.1
# version: 0.1
# author: Leon Scheltema
# license: CC0
# x-poshcode-id: 4507
# x-archived: 2016-05-17T08:15:03
# x-published: 2016-10-07T12:47:00
#
#
# start setting
# end setting
# User input ESXi host
$vCenter = Read-Host "Enter ESXi host FQDN"
# Connect VIserver
Connect-VIServer $vCenter
# Esxcli command pass-through to retrieve vmfs volume details
$esxcli=get-esxcli -vmhost $vCenter
$esxcli.storage.vmfs.extent.list() | ft volumename,VMFSUUID -autosize
# User input Location for persistent scratch location
$VolumeName = Read-Host "Enter Disk VolumeName"
# Get advanced setting and update value with user input
Get-AdvancedSetting -Entity (Get-VMhost -Name $vCenter) -Name "ScratchConfig.ConfiguredScratchLocation" | Set-AdvancedSetting -Value "/vmfs/volumes/$VolumeName" -Confirm:$False
# Disconnect VIserver
Disconnect-VIServer -Confirm:$false