The scratch partition on an ESXi host stores log information and will be set to the RAM drive by default.
This means that any information written there will not survive a reboot, or could interfere with the stability of the host in low memory situations.
Getting and setting the scratch location is quite easy with PowerCLi.
The code below shows some common usage scenarios of the Get/Set-AdvancedSetting command with scratch locations.
# connect to vCenter or host
connect-viserver vcenter.testlab.local
# will ask for credentials
# get scratch locaton of host called Host01.testlab.local
get-vmhost Host01.testlab.local | Get-AdvancedSetting -Name "ScratchConfig.ConfiguredScratchLocation"
# get scratch locaton of all connected hosts
get-vmhost | Get-AdvancedSetting -Name "ScratchConfig.ConfiguredScratchLocation"
# set the scratch location of Host01 to "/vmfs/volumes/DatastoreName01/HostLogs-Host01"
get-vmhost Host01.testlab.local | Get-AdvancedSetting -Name "ScratchConfig.ConfiguredScratchLocation" | Set-AdvancedSetting -Value "/vmfs/volumes/DatastoreName/HostLogs-Host01"
# loop through each host and set the scratch location to "/vmfs/volumes/DataStore011/HostLogs-(hostname)", removing the domain name from the host name
foreach ($vHost in get-vmhost)
{
write-host "Setting Scratch on host " + $vHost.name + " to " + ("/vmfs/volumes/DataStore01/HostLogs/" + (($vHost.name).replace(".testlab.local",''))) -ForegroundColor Yellow
$vHost | Get-AdvancedSetting -Name "ScratchConfig.ConfiguredScratchLocation" | Set-AdvancedSetting -Value ("/vmfs/volumes/DataStore01/HostLogs/" + (($vHost.name).replace(".testlab.local",''))) -Confirm:$false
}
# same as above but the domain and datastore names are in variables (THE SCRATCH LOCATION PATH IS CASE SENSITIVE)
# loop through each host and set the scratch location to "/vmfs/volumes/(DataStore)/HostLogs-(hostname)"
$DataStore = "NAS002-DS03" #"DataStore01"
$Domain = ".jase.local" #".testlab.local"
foreach ($vHost in get-vmhost)
{
write-host "Setting Scratch on host " $vHost.name " to " ("/vmfs/volumes/$DataStore/HostLogs/" + (($vHost.name).replace($Domain,''))) -ForegroundColor Yellow
$vHost | Get-AdvancedSetting -Name "ScratchConfig.ConfiguredScratchLocation" | Set-AdvancedSetting -Value ("/vmfs/volumes/$DataStore/HostLogs/" + (($vHost.name).replace($Domain,''))) -Confirm:$false
}
The first example (line 7) will get a specific host and pipe that host object in to the Get-AdvancedSetting command that returns the contents of the advanced host setting ScratchConfig.ConfiguredScratchLocation
The second example (line 10) is the same as the first but without the host name. The get-vmhost command will pipe an array of all vmHosts to the Get-AdvancedSetting command, that will list the scratch location for all the hosts you are connected to.
The third example (line 13) builds on the first. Here we are piping the output of the Get-AdvancedSetting
command in to the Set-AdvancedSetting
command and giving it a basic string. The string or full path is case sensitive.
The fourth example (line 17) loops through each host and uses the host name as part of the scratch path. Very handy for setting multiple hosts.
The fifth example (line 25) is the same as the fourth except the domain and datastore names are supplied from variables. This makes that piece of code more portable.