Here's the updated script:
# load the VMware module
$VimAutoCore = "VMware.VimAutomation.Core"
if ( (Get-PSSnapin -Name $VimAutoCore -ErrorAction SilentlyContinue) -eq $null ) {
Write-Host "loading $VimAutoCore powershell module"
Add-PsSnapin $VimAutoCore
}
#connect to the vCenter Server
$vcenter = Read-Host "Please enter the vCenter Hostname or IP Address"
#this will prompt the user to enter the user name and password to connect to the vCenter
Write-Host "Connecting to vCenter Server $vcenter" -ForegroundColor Yellow
Connect-VIServer -Server $vcenter -ErrorAction Stop -Protocol https
#prompt for ClusterName
$clustername = Read-Host "Please enter the Cluster name"
$cluster = Get-Cluster -name $clustername
Get-Cluster $cluster | Get-VMHost | Get-VMHostStorage -RescanAllHba
$hostsincluster = Get-VMHost -Location $cluster
ForEach($esx in $hostsincluster){
# Check for unresolved UUID
$VMHost = $esx
$HstSys = Get-View $esx.id
$HstDsSys = Get-View $HstSys.ConfigManager.DatastoreSystem
$UnresVols = @($HstDsSys.QueryUnresolvedVmfsVolumes())
# Resolve UUID for each on each ESXi host in the cluster
$HstSSys = Get-view $esx.StorageInfo
$UnresVols | %{
$Extent = $_.Extent
$DevicePath = $Extent.DevicePath
$ResSpec = New-Object Vmware.Vim.HostUnresolvedVmfsResolutionSpec[](1)
$ResSpec[0].ExtentDevicePath = $DevicePath
$ResSpec[0].UuidResolution = “forceMount”
$HstSSys.ResolveMultipleUnresolvedVmfsVolumes($ResSpec)
}
# Rescan for VMFS volumes
$VMHost | Get-VMHostStorage -RescanVmfs
}
Disconnect-VIServer $vcenter -Confirm:$false