If there is more than 1 unresolved LUN, the $UNresVols will be an array.
That means that you would need to run the complete step 3 in another ForEach loop, in fact executing step 3 for each unresolved LUN.
Something like this
....
$UnresVols = @($HstDsSys.QueryUnresolvedVmfsVolumes())
# Do step 3
$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)
}
# Do step 4
$esx | Get-VMHostStorage -RescanVmfs
....
Note that the first line in this extract, forces $UnresVols to be an array, even if there is only 1 unresolved LUN