VMware Cloud Community
Hemijimi
Contributor
Contributor
Jump to solution

Get-View issue

I am trying to get the host name and version number of the hosts in a specific datacenter. I may be way off, but here is what I am using so far:

$servers = Get-Datacenter  "My DataCenter"  | Get-Vmhost

foreach  ($server in $servers)

{

Get-View -ViewType HostSystem -Property Name,Config.Product | select Name, {$_.config.Product.FullName} | Export-CSV  P:\mypath

}

The issue I am having is that the for loop is running against the entire vCenter and not the variable so the output is all host names and version numbers for the vCenter server?  I have verified that the variable $servers includes just the hosts in the datacenter that I intended. What am I missing here?  

Thanks

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You are doing a general Get-View against the complete environment, that will return all HostSystems.

But there is in fact no need to the ForEach loop and the Get-View, you can access that property directly via the ExtensionData property.

Something like this

Get-Datacenter  "My DataCenter"  | Get-Vmhost |

select Name, @{N='FullName';E={$_.ExtensionData.Config.Product.FullName}} |

Export-CSV  P:\mypath\report.csv -NoTypeInformation -UseCulture

 


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

You are doing a general Get-View against the complete environment, that will return all HostSystems.

But there is in fact no need to the ForEach loop and the Get-View, you can access that property directly via the ExtensionData property.

Something like this

Get-Datacenter  "My DataCenter"  | Get-Vmhost |

select Name, @{N='FullName';E={$_.ExtensionData.Config.Product.FullName}} |

Export-CSV  P:\mypath\report.csv -NoTypeInformation -UseCulture

 


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

0 Kudos
Hemijimi
Contributor
Contributor
Jump to solution

Thanks for your help Luc.

0 Kudos