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($_.Summary.QuickStats.overallMemoryUsage/1000, 2)}},
@{N="TotalMem (GB)";E={[math]::round($_.Hardware.MemorySize / 1000000000, 2)}} |
Export-Csv MyOutputFile.csv
Thanks as always.
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
Get-VM | Select Tag
behavior with PowerCLI 6.5 & VC 5.5.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.