VMware Cloud Community
lucianopm90
Contributor
Contributor
Jump to solution

Get statistics by VM folder

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.

summary.png

Thank you

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

One way to do that could be

$folders = Get-Folder -Location VIRTUAL_MACHINES -Type VM -NoRecursion

$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

View solution in original post

10 Replies
LucD
Leadership
Leadership
Jump to solution

You could do something like this

$folderName = 'MyFolder'

$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

lucianopm90
Contributor
Contributor
Jump to solution

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)}}

}

0 Kudos
LucD
Leadership
Leadership
Jump to solution

One way to do that could be

$folders = Get-Folder -Location VIRTUAL_MACHINES -Type VM -NoRecursion

$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

Dazink
Contributor
Contributor
Jump to solution

Would there be a way to do this but track the metrics over a period of time per folder?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That would require using the Get-Stat cmdlet.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Gafannen
Contributor
Contributor
Jump to solution

Hello LucD,

Would be possible to get it to work for top level Folders?

0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

0 Kudos
Gafannen
Contributor
Contributor
Jump to solution

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>

0 Kudos
LucD
Leadership
Leadership
Jump to solution

I forgot the hidden 'vm' folder.
Code above has been updated


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Gafannen
Contributor
Contributor
Jump to solution

Thank you LucD, it is working now. 👍

0 Kudos