# 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: 6202
# x-archived: 2016-05-12T10:05:33
# x-published: 2016-02-05T04:51: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
