Hi All,
Currently we are trying to generating report on VMs allocation with respect to Teams.
Each VM will be having a custom attribute as Team and corresponding team name is entered.
In below example I am illustrating the set of VMs belongs to 3 Teams.
Team: X
Setab01
Setab02
Setab03
Setab04
Team: Y
Setcd01
Setcd02
Setcd03
Team: Z
Setef01
Setef02
Team: X
Setgh01
Setgh02
Sample Output Needed:
Team Number of Sets Number of VMs
-------- ---------------------- ----------------------
X 2 6
Y 1 3
Z 1 2
Below script is returning only VM Set with respect to Number of VMs of each set
$vmnames = Get-VM
$vmname = $vmnames.name.substring(0,5) | Group-Object | select Name,Count
$vmad = @()
foreach($v in $vmname){
$vmcount = $v.count
$vmd = "" | select "VM Set","VMs Count"
$vmd."VM Name" = $v.name
$vmd."VMs Count" = $vmcount
$vmad += $vmd
}
$vmad
Ex: Output
VM Set VMs Count
----------- ----------------------
Setab 4
Setcd 3
Setef 2
Setgh 2
I am not able to get the desired output, Could some one help me.
Would something like this work for you?
$vmad = @()
Get-VM |
Group-Object -Property {(Get-Annotation -CustomAttribute Team -Entity $_).Value} | %{
$row = '' | Select Team,'VM Sets','VM Count'
$row.Team = $_.Name
$row.'VM Count' = $_.Group.Count
$row.'VM Sets' = ($_.Group | Group-Object -Property {$_.Name.substring(0,5)}).Count
$vmad += $row
}
$vmad
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Lucd,
Script is working fine.
We got additional requirement to add 3 more columns in the same script
Could you please help us to get the desired output.
If the VMs count in each Set is equal to 1 then it should be nominated under E
If the VMs count in each set is equal to 2 and less than 5 then it should be nominated under S
If the VMs count in each Set is equal to 9 and above then it should be nominated under I
Team: X
Setab01
Setab02
Setab03
Setab04
Setab05
Setab06
Setab07
Setab08
Setab09
Team: Y
Setcd01
Setcd02
Setcd03
Team: Z
Setef01
Setef02
Team: X
Setgh01
Setgh02
Sample Output:
Team I S E Total VMs Count
--------- --- ----- ---- ------------------------
X 1 1 0 10
Y 0 1 0 3
Z 0 1 0 2
I'm afraid that is not clear to me.
What happens for example when a Team has 3 sets, with these sets having 1,3 and 11 VMs?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
1 set is having 1 VM so it has to be nominated under E ( VM Count is 1 for this set)
1 set is having 3 VMs so it has to be nominated under S ( VM Count is 3 which is greater than 2 and less than 5)
1 set is having 11 VMs so it has to be nominated under I ( VM Count is 11 which is greater than 9)
So you don't need to see the number of sets anymore in the report?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes Lucd,
Instead of Number of sets, it is spanned as I , S & E as column labels used for individual sets with respect to VM Count
Like this?
Note that you will be missing sets with 6 to 8 VMs.
vmad = @()
Get-VM |
Group-Object -Property {(Get-Annotation -CustomAttribute Team -Entity $_).Value} | %{
$obj = New-Object PSObject -Property @{
Team = $_.Name
'VM Count' = $_.Group.Count
E = 0
S = 0
I = 0
}
$_.Group | Group-Object -Property {$_.Name.substring(0,5)} | %{
if($_.Group.Count -eq 1){
$obj.E += 1
}
elseif($_.Group.Count -lt 5){
$obj.S += 1
}
elseif($_.Group.Count -ge 9){
$obj.I += 1
}
}
$vmad += $obj
}
$vmad
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi Lucd,
In script '}' is missing, I have added it.
Output of the Script is below.
Count Name Group
-------- --------- ---------
Name is listing null in the report
But I am expecting Output in below format.
Team I S E Total VMs Count
--------- --- ----- ---- ------------------------
X 1 1 0 10
Y 0 1 0 3
Z 0 1 0 2
Oops, yes, there was a typo.
I corrected the code above, can you try it again?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference