Example with 3 test VMs created. The third doesn't have any TAG associated to it.
Get-VM | where {$_.Name -match "TAG*"}| ForEach-Object {
$VM = $_
$Tag = $_ | get-tagassignment
If($Tag){
$Tag.tag| foreach-object{
$Output = New-Object -Type PSObject -Prop ([ordered]@{
'VM' = $VM
'Host' = $VM.VMhost
'Notes' = $VM.Notes
'TagCategory' = $_.Category
'TagName' = $_.Name
})
Return $Output
}
}Else{
$Tag.tag| foreach-object{
$Output = New-Object -Type PSObject -Prop ([ordered]@{
'VM' = $VM
'Host' = $VM.VMhost
'Notes' = $VM.Notes
'TagCategory' = "NO TAG FOR THIS VM"
'TagName' = "NO TAG FOR THIS VM"
})
Return $Output
}
}
} | ogv
And the output looks like: