Hi there,
I am making use of tags so I can identify which VM are up for review. I have a category called "Expiry Date" and they contain tags named after the months.
I want to get a list of VM which do not have a tag assigned belonging to the "Expiry Date" Category.
The following returns my VM and associated tags
get-vm | select name,@{N="Tag";E={(get-tagassignment $_.name).tag.category}}
An example output would be as follows
Name Tag
vm1
vm2 Expiry Date
vm3 Expiry Date
vm4
I'd like to retrieve just vm1 and vm4 as they have no tag associated but can't seem to make it work
I tried appending "where {$_.tag -eq $null}" but that gives me the exact same output
I also tried using the following command
get-vm | select name,@{N="Tag";E={(get-tagassignment $_.name).tag | where { $_.tag -notmatch "Expiry Date"}}}
This also returns all VM regardless whether they have tag value.
Any ideas as to what I am doing wrong?
Try something like this
$cat = Get-TagCategory -Name 'Expiry Date'
Get-VM |
Where{Get-TagAssignment -Entity $_ -Category $cat} |
Select Name,@{N="Tag";E={(Get-TagAssignment $_.name).tag}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this
$cat = Get-TagCategory -Name 'Expiry Date'
Get-VM |
Where{Get-TagAssignment -Entity $_ -Category $cat} |
Select Name,@{N="Tag";E={(Get-TagAssignment $_.name).tag}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Bedankt Luc 🙂
This returned a list with VM having a tag in the category. Since I wanted a list of the VM that did not have a tag in that category I modified it to be
Where{!(Get-TagAssignment -Entity $_ -Category $cat)} | Select Name
Got what I want now
Cheers
Oops, sorry about that.
Glad you found the solution yourself.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Can this script be modified to only include two specific clusters. We use VMware tagging for backups and the goal is to find new server builds that do not have a category of protection, so we can confirm we are not missing any servers from backups.
Just proceed the Get-MV with a Get-Cluster
Get-Cluster -Name cluster1,cluster2 | Get-VM |
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It seems to work with one cluster, but both of my clusters have spaces in the name, so it is giving me an error that it cannot find the second cluster. I tried to add quotes but it is not working
Get-Cluster -Name "cluster 1","cluster 2" | Get-VM |
I also tried
Get-Cluster -Name 'cluster 1','cluster 2' | Get-VM |
Are you saying that this
Get-Cluster -Name 'cluster 1','cluster 2'
doesn't return 2 cluster objects?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I was able to get it to work with quotes, but how can I output the results to an email, or file?
For a file, you could use Export-Csv, for an email you could use Send-MailMessage
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I was able to get it to work with quotes, but how can I output the results to an email, or file?
I have tried to export but the file is blank. It does not include the vm's without tags.
When I output to text the file is blank
I would need to see the code you are using to investigate
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
7 years later, but for the next guy like me.
I've found this works and doesn't truncate for easy copying:
get-vm | ?{ (get-tagassignment $_ -Category 'Expiry Date') -eq $null} | Format-Table -Property Name -AutoSize