Using PowerCLI to get a tag associated with ESXI Host

I have started using VMWare's Tag to assist in my reporting and filtering using powerCLI as my scripting tool. I have tags associated with both VMs and Hosts.

I can retrieve the tag associated with the VMs with script like this:

 Get-VM | Select Name,Guest,PowerState,VMHost,Tag,ResourcePool

Because tag is included as a returned attribute.

What I can't figure out is how to return the tab values from a Host or Datastore. Any ideas? I would like to add it to the following script:

Get-VMHost | Get-View | Select Name, @{N="Cluster";E={Get-Cluster -VMHost (Get-VMHost $_.Name)}}, @{N="DataCenter";E={Get-Datacenter -VMHost (Get-VMHost $_.Name)}}, @{N="Vendor";E={$_.Hardware.SystemInfo.Vendor}}, @{N="Model";E={$_.Hardware.SystemInfo.Model}}, @{N="CPU";E={$_.Hardware.CpuInfo.NumCpuPackages}}, @{N="CORES";E={$_.Hardware.CpuInfo.NumCpuCores}}, @{N="TotalMHZ";E={[math]::round($_.Hardware.CpuInfo.Hz / 1000000, 0)}}, @{N="UsedMem (GB)";E={[math]::round($_ 2)}}, @{N="TotalMem (GB)";E={[math]::round($_.Hardware.MemorySize / 1000000000, 2)}} |
Export-Csv MyOutputFile.csv

Thanks as always.

1

1 Answer

There's probably a more efficient way, but adding a property like this should work

@{N="tag";E={(Get-Tagassignment -Entity $_.Name).Tag.Name}}

What PowerCLI & vCenter versions are you running? I'm not recreating the described Get-VM | Select Tag behavior with PowerCLI 6.5 & VC 5.5.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like