logo

Powershell: Configure Local datastore as Persistent Storage for ESXi

 

Quick script on how to configure persistent storage on local datastore on each of the ESXi hosts.

Enjoy!

function ReturnLocalDatastore  ($vmhost)
{
	$data = $VMHost | Get-Datastore | Get-View | Select-Object  @{n="Name";e={$_.Name}}, @{n="Multi-Access";e={$_.Summary.MultipleHostAccess}} |  where {$_."Multi-Access" -eq $false} 
	
	return $data.Name
}


foreach ($VMHost in Get-VMHost)
{
	$currentSetting =  Get-AdvancedSetting -Entity $VMHost -Name "Syslog.global.logDir"
	if ($currentSetting.value -eq "[] /scratch/log")
	{
		$VMHostName = $VMHost.Name.Split('.')
		$localDS = ReturnLocalDatastore -VMHost $vmhost
		$VMHostDatastore = "[$localDS] /systemlogs"
		Write-Host " $vmhost - $VMHostDatastore"
		
		Get-AdvancedSetting -Entity $VMHost -Name "Syslog.global.logDir" | Set-AdvancedSetting -Value $VMHostDatastore -Confirm:$false
	}	
}

Leave a Reply

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.