Thanks Luc, i used the below code. But in my env we have 4205 VMs but i got report of only 3809 VMs.
And i got around 141 error as below. Am i missing something ?
MethodInvocationException:
Line |
19 | $val.Add($tag.Tag.Category.Name,$tag.Tag.Name)
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Exception calling "Add" with "2" argument(s): "Item has already been added. Key in dictionary: 'Customer' Key being added: 'Customer'"
MethodInvocationException:
$tagCat = @()
$tagTab = @{}
foreach($tag in (Get-TagAssignment)){
$tagCat += $tag.Tag.Category.Name
$key = $tag.Entity.Name
if($tagTab.ContainsKey($key)){
` $val = $tagTab.Item($key)
}
else{
$val = @{}
}
$val.Add($tag.Tag.Category.Name,$tag.Tag.Name)
$tagTab[$key] = $val
}
$tagCat = $tagCat | Sort-Object -Unique
$tags = foreach($row in ($tagTab.GetEnumerator() | Sort-Object -Property Key)){
$obj = New-Object PSObject -Property @{
VM = $row.Key
}
$tagCat | %{
$obj | Add-Member -Name $_ -Value $row.Value[$_] -MemberType NoteProperty
}
$obj
}
$tags | Export-Csv tags1.csv -NoTypeInformation -UseCulture
Thanks
Bikash