Automation

 View Only
  • 1.  Count VMs based on multiple tags

    Posted Apr 28, 2021 12:47 PM

    Hi,

     

    We currently have 5 tag categories with several tags within each of the categories, defining our backup jobs.

    Backup_Location:
    Backup_dk
    Backup_de
    Backup_pl
    Backup_nl
    Backup_Job:
    Backup_v1
    Backup_v2
    Backup_v3
    Backup_v4
    Backup_Retention:
    Backup_7_days
    Backup_14_days
    Backup_21_days
    Backup_31_days
    Backup_domain:
    Backup_production
    Backup_test
    Backup_dmz
    Backup_Configuration:
    Backup_Disabled
    Backup_Custom
    Backup_Enabled

     

    Due to limitations in our backup product, we have to have an maximum of 200VMs in each backup job.

    So the idea was to find all VMs that have the same value in Backup_Location, Backup_Retention, Backup_domain and Backup_Job , and then count the number of VMs within each of these, to find the Backup_Job tag, with the least amount of VMs in it.

     

    We therefor tried to use Get-VM -Tag Backup_dk,Backup_7_days,Backup_production , but it seems that the -Tag parameter dont handle multiple tags that well - it throws an error, yet it returns values.

    Ive tried several other things (foreach inside foreach, Get-TagAssignment, etc), but its not an ideal option, and therefor takes few minutes to execute, due to the large number of VMs.

     

    So what is the best way to solve the "math problem"? 

     

    Any inputs would be much appreciated!  



  • 2.  RE: Count VMs based on multiple tags

    Posted Apr 28, 2021 12:58 PM

    Something like this?

    Get-Tag -Name Backup* -PipelineVariable tag | 
    ForEach-Object -Process {
        New-Object -TypeName PSObject -Property @{
            Tag = $tag.Name
            VMNr = (Get-VM -Tag $tag.Name).Count
        }
    }
    


  • 3.  RE: Count VMs based on multiple tags

    Posted Apr 28, 2021 01:10 PM

    Hi,

     

    Almost! 

    I need all VMs that have the same values in these categories:

    Backup_Location, Backup_Retention, Backup_Domain 

    And then find the Backup_Job tag, with the least number of VMs, that has the 3 tags above defined.

     



  • 4.  RE: Count VMs based on multiple tags

    Posted Apr 28, 2021 01:17 PM

    What do you mean by "same values in these categories"?

    These categories have different tags.