Hi guys, I already took a look at the other discussions, but I haven't found exactly what I need.
I saw some examples of LucD, but none that helped me. We want to generate a resource usage report for each VM folder. In the graphical interface I have the information, as shown in the image below, but via PowerCLI I didn't find it.
Thank you
One way to do that could be
$report = @()
foreach($folder in $folders){
$cpu,$memory,$storage = Get-Folder -Name $folder | Get-VM |
select @{N='CPU';E={$_.ExtensionData.Summary.Quickstats.OverallCpuUsage}},
@{N='Memory';E={$_.ExtensionData.Summary.Quickstats.GuestMemoryUsage}},
UsedSpaceGB |
Measure-Object -Property CPU,Memory,UsedSpaceGB -Sum |
Select -ExpandProperty Sum
$report += '' | Select @{N='Folder';E={$folder}},@{N='CPU';E={$cpu}},@{N='Memory';E={$memory}},@{N='Storage';E={[math]::Round($storage,2)}}
}
$report | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You could do something like this
$cpu,$memory,$storage = Get-Folder -Name $folderName | Get-VM |
select @{N='CPU';E={$_.ExtensionData.Summary.Quickstats.OverallCpuUsage}},
@{N='Memory';E={$_.ExtensionData.Summary.Quickstats.GuestMemoryUsage}},
UsedSpaceGB |
Measure-Object -Property CPU,Memory,UsedSpaceGB -Sum |
Select -ExpandProperty Sum
'' | Select @{N='Folder';E={$folderName}},@{N='CPU';E={$cpu}},@{N='Memory';E={$memory}},@{N='Storage';E={[math]::Round($storage,2)}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks alot LucD, that was exactly what I needed. I put a foreach to get the information for each folder and now I would like to export it to a CSV. Can you help me with this?
$folders = Get-Folder -Location VIRTUAL_MACHINES -Type VM -NoRecursion
foreach($folder in $folders){
$cpu,$memory,$storage = Get-Folder -Name $folder | Get-VM |
select @{N='CPU';E={$_.ExtensionData.Summary.Quickstats.OverallCpuUsage}},
@{N='Memory';E={$_.ExtensionData.Summary.Quickstats.GuestMemoryUsage}},
UsedSpaceGB |
Measure-Object -Property CPU,Memory,UsedSpaceGB -Sum |
Select -ExpandProperty Sum
'' | Select @{N='Folder';E={$folder}},@{N='CPU';E={$cpu}},@{N='Memory';E={$memory}},@{N='Storage';E={[math]::Round($storage,2)}}
}
One way to do that could be
$report = @()
foreach($folder in $folders){
$cpu,$memory,$storage = Get-Folder -Name $folder | Get-VM |
select @{N='CPU';E={$_.ExtensionData.Summary.Quickstats.OverallCpuUsage}},
@{N='Memory';E={$_.ExtensionData.Summary.Quickstats.GuestMemoryUsage}},
UsedSpaceGB |
Measure-Object -Property CPU,Memory,UsedSpaceGB -Sum |
Select -ExpandProperty Sum
$report += '' | Select @{N='Folder';E={$folder}},@{N='CPU';E={$cpu}},@{N='Memory';E={$memory}},@{N='Storage';E={[math]::Round($storage,2)}}
}
$report | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Would there be a way to do this but track the metrics over a period of time per folder?
That would require using the Get-Stat cmdlet.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello LucD,
Would be possible to get it to work for top level Folders?
You can start with
$root = Get-Folder -Name Datacenters | Get-Folder -Name vm
$folders = Get-Folder -Location $root -NoRecursion -Type VM
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you for your fast answer, but unfortunately it returns nothing.
PS C:\Users\xxxx-admin> $root
Name Type
---- ----
Datacenters Datacenter
PS C:\Users\xxx-admin> Get-Folder -Location $root -Type VM -NoRecursion
PS C:\Users\xxx-admin>
I forgot the hidden 'vm' folder.
Code above has been updated
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thank you LucD, it is working now. 👍