I would like some help with scripting the following steps to cerate a scratch partition on all hosts that do not have one and then reprot back to me which hosts had to have one created.
all of my ESXi hosts have a boot LUN with space, all the boot LUNs are named with the same naming conveiton i.e. "hostname-localstorage"
I'd like to come up with a script that will check each host in a cluster for a scaratch partition, if it does not have one create the folder ".locker-hostname" on local storrage and then set the scratch partition to the new location. Then report back to me which hosts already had a scratch partition and which ones it had to create a scratch parition for so I can then plan a good time to put the hosts with newly created scratch partitions into mainenance mode and reboot them.
I pasted the manual way to do this below. I'd appreciate any help anyone can give and it willbe much appreciated. I am trying to avoid doing the below 1000 times. Thanks in advance...
- Open a command prompt where the PowerCLI is installed.
- Connect to the ESXi host using the command:
connect-viserver ESXHostnameOrIP
- Obtain a list of datastores reachable from this ESXi host using the command:
Get-Datastore
- Mount a datastore read/write as a PSDrive using the command:
New-PSDrive -Name "mounteddatastore" -Root \ -PSProvider VimDatastore -Datastore (Get-Datastore "DatastoreName")
- Access the new PSDrive using the command:
Set-Location mounteddatastore:
- Create a uniquely-named directory for this ESXi host using the command:
New-Item "DirectoryName" -ItemType directory
For example:New-Item ".locker-ESXHostname" -ItemType directory
- Check the current value of the
ScratchConfig.ConfiguredScratchLocation
configuration option using the command:Get-VMHostAdvancedConfiguration -Name "ScratchConfig.ConfiguredScratchLocation"
- Change the
ScratchConfig.ConfiguredScratchLocation
configuration option, specifying the full path to the directory created in Step 6, using the command:Set-VMHostAdvancedConfiguration -Name "ScratchConfig.ConfiguredScratchLocation" -Value "/vmfs/volumes/DatastoreName/DirectoryName"
For example:Set-VMHostAdvancedConfiguration -Name "ScratchConfig.ConfiguredScratchLocation" -Value "/vmfs/volumes/Datastore1/.locker-ESXHostname"
- Put the ESXi host in maintenance mode and reboot for the configuration change to take effect.
Mike P