Not 100% sure that I understood what you were trying to do, but I suspect it was to get the path to the standalone ESXi.
Try it like this
####################
write-host"Standalone hosts:"-foregroundcolorgreen
#TM hosts not in cluster
$hostlist=Get-VMHost|where{$_.ExtensionData.Parent.Type-ne"ClusterComputeResource"}
foreach ($host1in$hostlist) {
#get folder
$path=@($host1.Name)
$parent=Get-View$host1.ExtensionData.Parent
While ($parent.parent){
$parent=Get-View$parent.parent
if("Datacenters","host"-notcontains$parent.Name){
$path+=$parent.Name
}
}
[array]::Reverse($path)
$path= [string]::Join('/',$path)
write-host"$path"
$out=get-vmhost$host1|get-vmhosthba|get-scsilun|get-scsilunpath|
Select-ExpandPropertySanID-unique-ErrorAction"SilentlyContinue"
write-host"$out"
write-host" "
}
####################