VMware Cloud Community
bairstowscott
Contributor
Contributor

VIObject error message

Hi

Just wondering why I am getting the below error message....

####################
write-host "Standalone hosts:" -foregroundcolor green
#TM hosts not in cluster
$hostlist = Get-VMHost |where{$_.ExtensionData.Parent.Type -ne "ClusterComputeResource"} | Select Name

foreach ($host1 in $hostlist) {
#get folder
$path = @()
$parent = Get-View $host1.ExtensionData.ResourcePool
While ($parent.parent){ 
    $parent = Get-View $parent.parent
    $path += $parent.Name
}
$path = "$path".split(" ")[1]
write-host "$path"


$out = get-vmhost $host1 | get-vmhosthba | get-scsilun | get-scsilunpath | Select -ExpandProperty SanID -unique -ErrorAction "SilentlyContinue"


write-host "$out"
write-host " "
}
####################

Capture.PNG

0 Kudos
3 Replies
LucD
Leadership
Leadership

Try changing this line

$hostlist = Get-VMHost |where{$_.ExtensionData.Parent.Type -ne "ClusterComputeResource"} | Select Name

into this

$hostlist = Get-VMHost |where{$_.ExtensionData.Parent.Type -ne "ClusterComputeResource"}

You need to use the HostSystem object, not just the Name property


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

bairstowscott
Contributor
Contributor

The script now works but I am still getting his error message

Capture.PNG

0 Kudos
LucD
Leadership
Leadership

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:" -foregroundcolor green
#TM hosts not in cluster
$hostlist = Get-VMHost |where{$_.ExtensionData.Parent.Type -ne "ClusterComputeResource"}
foreach ($host1 in $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 -ExpandProperty SanID -unique -ErrorAction "SilentlyContinue"


 
write-host "$out"
 
write-host " "
}
####################


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos