[英]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. 我已经开始使用VMWare的Tag来协助使用powerCLI
作为脚本工具进行报告和过滤。 I have tags
associated with both VMs
and Hosts
. 我有与VMs
和Hosts
相关联的tags
。
I can retrieve the tag associated with the VMs
with script like this: 我可以使用以下脚本检索与VMs
关联的标签:
Get-VM | Select Name,Guest,PowerState,VMHost,Tag,ResourcePool
Because tag
is included as a returned attribute. 因为将tag
包含为返回的属性。
What I can't figure out is how to return the tab
values from a Host or Datastore. 我不知道如何从主机或数据存储中返回tab
值。 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? 您正在运行哪些PowerCLI和vCenter版本? I'm not recreating the described Get-VM | Select Tag
我没有重新创建描述的Get-VM | Select Tag
Get-VM | Select Tag
behavior with PowerCLI 6.5 & VC 5.5. Get-VM | Select Tag
使用PowerCLI 6.5和VC 5.5的Get-VM | Select Tag
行为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.