{"id":77,"date":"2019-06-27T23:13:06","date_gmt":"2019-06-27T22:13:06","guid":{"rendered":"http:\/\/192.168.8.14\/?p=77"},"modified":"2019-07-06T21:21:33","modified_gmt":"2019-07-06T20:21:33","slug":"getting-and-setting-the-scratch-location","status":"publish","type":"post","link":"https:\/\/www.jasonstreet.com\/?p=77","title":{"rendered":"Getting and Setting the Scratch location"},"content":{"rendered":"\n<p>The scratch partition on an ESXi host stores log information and will be set to the RAM drive by default. <br>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.<\/p>\n\n\n\n<p>Getting and setting the scratch location is quite easy with PowerCLi.<\/p>\n\n\n\n<p>The code below shows some common usage scenarios of the Get\/Set-AdvancedSetting command with scratch locations.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\n# connect to vCenter or host\nconnect-viserver vcenter.testlab.local\n# will ask for credentials\n\n\n# get scratch locaton of host called Host01.testlab.local\nget-vmhost Host01.testlab.local | Get-AdvancedSetting -Name &quot;ScratchConfig.ConfiguredScratchLocation&quot;\n\n# get scratch locaton of all connected hosts\nget-vmhost | Get-AdvancedSetting -Name &quot;ScratchConfig.ConfiguredScratchLocation&quot;\n\n# set the scratch location of Host01 to &quot;\/vmfs\/volumes\/DatastoreName01\/HostLogs-Host01&quot;\nget-vmhost Host01.testlab.local | Get-AdvancedSetting -Name &quot;ScratchConfig.ConfiguredScratchLocation&quot; | Set-AdvancedSetting -Value &quot;\/vmfs\/volumes\/DatastoreName\/HostLogs-Host01&quot;\n\n\n# loop through each host and set the scratch location to &quot;\/vmfs\/volumes\/DataStore011\/HostLogs-(hostname)&quot;, removing the domain name from the host name\nforeach ($vHost in get-vmhost)\n{\n  write-host &quot;Setting Scratch on host &quot; + $vHost.name + &quot;  to &quot; + (&quot;\/vmfs\/volumes\/DataStore01\/HostLogs\/&quot; + (($vHost.name).replace(&quot;.testlab.local&quot;,&#039;&#039;))) -ForegroundColor Yellow\n  $vHost | Get-AdvancedSetting -Name &quot;ScratchConfig.ConfiguredScratchLocation&quot; | Set-AdvancedSetting -Value  (&quot;\/vmfs\/volumes\/DataStore01\/HostLogs\/&quot; + (($vHost.name).replace(&quot;.testlab.local&quot;,&#039;&#039;))) -Confirm:$false\n}\n\n# same as above but the domain and datastore names are in variables (THE SCRATCH LOCATION PATH IS CASE SENSITIVE)\n# loop through each host and set the scratch location to &quot;\/vmfs\/volumes\/(DataStore)\/HostLogs-(hostname)&quot;\n$DataStore = &quot;NAS002-DS03&quot; #&quot;DataStore01&quot;\n$Domain = &quot;.jase.local&quot; #&quot;.testlab.local&quot;\nforeach ($vHost in get-vmhost)\n{\n  write-host &quot;Setting Scratch on host &quot; $vHost.name &quot;  to &quot; (&quot;\/vmfs\/volumes\/$DataStore\/HostLogs\/&quot; + (($vHost.name).replace($Domain,&#039;&#039;))) -ForegroundColor Yellow\n  $vHost | Get-AdvancedSetting -Name &quot;ScratchConfig.ConfiguredScratchLocation&quot; | Set-AdvancedSetting -Value  (&quot;\/vmfs\/volumes\/$DataStore\/HostLogs\/&quot; + (($vHost.name).replace($Domain,&#039;&#039;))) -Confirm:$false\n}\n\n\n\n<\/pre><\/div>\n\n\n<p>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<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>The third example (line 13) builds on the first. Here we are piping the output of the <code>Get-AdvancedSetting<\/code> command in to the  <code>Set-AdvancedSetting<\/code> command and giving it a basic string. The string or full path is case sensitive.<\/p>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[5,4],"tags":[15,12,13,14,6],"class_list":["post-77","post","type-post","status-publish","format-standard","hentry","category-powercli","category-powershell","tag-host","tag-powercli","tag-powershell","tag-scratch","tag-vmware"],"_links":{"self":[{"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/posts\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=77"}],"version-history":[{"count":0,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=\/wp\/v2\/posts\/77\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=77"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=77"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jasonstreet.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}