This is the command i have been trying but not giving vms without tags
Get-VM | Get-TagAssignment
where {($_.Tag -eq $null) -or ($_.Tag -ne $null)} |
Select @{N='VM';E={$_.Entity.Name}},`
@{N='TagName';E={$_.Tag}},`
@{N="Cluster";E={Get-Cluster -VM $_.Entity.Name}},`
@{N="ESX Host";E={Get-VMHost -VM $_.Entity.Name}}
When there is no tag assigned to a VM, nothing will be returned and there will be no $_.Tag property.
You could do something like this
$tags = Get-TagAssignment -Entity $vm
If($tags -eq $null){
'' | Select @{N='VM';E={$vm.Name}},
@{N='TagName';E={}},
@{N="Cluster";E={Get-Cluster -VM $vm}},
@{N="ESX Host";E={Get-VMHost -VM $vm}}
}
else{
$tags | Select @{N='VM';E={$_.Entity.Name}},
@{N='TagName';E={$_.Tag.Name}},
@{N="Cluster";E={Get-Cluster -VM $vm}},
@{N="ESX Host";E={Get-VMHost -VM $vm}}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks alot LucD, now i am want to send the output of this in via email. Can you please help me with that.
You can use the Send-MailMessage cmdlet for that.
There are plenty of examples available in this community.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference