Hi,
I try to create a report for counting VM´s memery and cpu useby certain Os and Sort on Cluster level. I want to improve the output by meassure the mem and cpu count on clusterlevel for a certian OS Type
Someting like this:
Name | cluster1 | cluster2 | cluster3 | cluster4 | cluster5 | cluster6 |
vcpu | 12 | 34 | 81 | 89 | 0 | 94 |
ram | 0 | 8 | 19 | 19 | 0 | 178 |
UsedGB | 12 | 34 | 1 | 455 | 6 | 12 |
$mycluster = Get-Cluster
$myCol = @()
$error.Clear()
foreach ($vmlist in $mycluster)
{
foreach ($vm1 in $vmlist)
{
$vminfo = $vm1 | Select name,
@{n="2008";e={($_ | get-vm | Where {$_.powerstate -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows.*2008'}).count}},
@{n="MemoryGB";e={$_ | get-vm | Where $_.powerstate -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows.*2008' | Measure-Object -property -sum "memoryGB" }
@{n="vcpu";e={$_ | get-vm | Where $_.powerstate -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows.*2008' | Measure-Object -property -sum "Num CPUs" }
@{n="UsedGB";e={$_ | get-vm | Where $_.powerstate -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows.*2008' | Measure-Object -property -sum "UsedGB" }
#@{n="memory";e={($_ | get-vm | Where {$_.powerstate -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows.*2008' } | Measure-Object -sum "memoryGB"}},
$myCol += $VMInfo
}
}
$myCol
Producing the data could be done like this.
ForEach-Object -Process {
$vms = Get-VM -Location $cluster |
where{$_.powerstate -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows.*2008'}
New-Object -TypeName PSObject -Property ([ordered]@{
Name = $cluster.Name
2008 = $vms.Count
MemoryGB = ($vms.MemoryGB | Measure-Object -Sum ).Sum
vCPU = ($vms.NumCpu | Measure-Object -Sum ).Sum
UsedGB = [math]::Round(($vms.UsedSpaceGB | Measure-Object -Sum ).Sum,1)
})
}
Transposing the result is something that might be a bit harder, if not impossible with the current property names and values, to accomplish.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
And besides the obvious error in the foreach loops, is there a question in here?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
question is, how i could do a report on Clusterlevel to measure the ram,cpu and diskspace usage of all windows 2008 servers...in sum.
the script is buggy because I was struggle in the middle,
Producing the data could be done like this.
ForEach-Object -Process {
$vms = Get-VM -Location $cluster |
where{$_.powerstate -eq 'PoweredOn' -and $_.Guest.OSFullName -match 'Windows.*2008'}
New-Object -TypeName PSObject -Property ([ordered]@{
Name = $cluster.Name
2008 = $vms.Count
MemoryGB = ($vms.MemoryGB | Measure-Object -Sum ).Sum
vCPU = ($vms.NumCpu | Measure-Object -Sum ).Sum
UsedGB = [math]::Round(($vms.UsedSpaceGB | Measure-Object -Sum ).Sum,1)
})
}
Transposing the result is something that might be a bit harder, if not impossible with the current property names and values, to accomplish.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
awesome, thanks LUC