Hello everyone!
There is a script that collects some statistics. I want to add VM tags to it, but I can't find them in the properties. There is no - $VM.ExtensionData. Here, too, is $VM.Guest. How to add? Help!
Get-Cluster | Get-VM -PipelineVariable vm | Get-NetworkAdapter |
Select @{N='VM';E={$vm.Name}},NetworkName, MacAddress,
@{N=”IP Address”;E={
$nic = $_
$ips = ($vm.Guest.Nics | where{$_.Device.Name -eq $nic.Name}).IPAddress
($ips | where{([ipaddress]$_).AddressFamily -eq 'InterNetwork'}) -join '|'}},
@{N='Gateway';E={($VM.ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute.Gateway.IPaddress | where{$_ -ne $null}) }},
@{N="DNS";E={$vm.ExtensionData.Guest.IpStack.DnsConfig.IpAddress}},
@{N="Subnet Mask";E={$vm.ExtensionData.Guest.Net.IpConfig.IpAddress.PrefixLength}},
@{N='OS';E={$vm.Guest.OSFullName}},
@{N='CreateDate';E={$vm.CreateDate}},
@{N="Tags";E={??????????????}, - help here
@{N="Attributes";E={[string]::Join('|',($VM.ExtensionData.Value.Value))}} | Out-GridView
You will have to use the Get-TagAssignment cmdlet and use the $vm on the Entity parameter.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks @LucD
Added:
@{N='Tags';E={(Get-TagAssignment -Entity $VM).Tag -join '|'}},
I thought it was in the properties