VMware Cloud Community
Dimon_SPB
Contributor
Contributor
Jump to solution

Get vCenter data via powerCLI

How you can get this data using PowerCLI?

vCenter_info.jpg

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do something like this

ForEach-Object -InputObject $global:DefaultVIServers -Process {
    $totalCPu = $usedCpu = $totalMem = $usedMem = $totalStor = $usedStor = 0
    
    Get-View -ViewType HostSystem -Property 'Summary' -PipelineVariable esx |
    ForEach-Object -Process {
        $totalCpu += $esx.Summary.Hardware.CpuMhz * $esx.Summary.Hardware.numCpuCores
        $usedCpu += $esx.Summary.QuickStats.OverallCpuUsage
        $totalMem += $esx.Summary.Hardware.MemorySize
        $usedMem += $esx.Summary.QuickStats.OverallMemoryUsage
    }
    Get-View -ViewType Datastore -Property 'Summary' -PipelineVariable ds  |
    ForEach-Object -Process {
        $totalStor += $ds.Summary.Capacity
        $usedStor += $ds.Summary.Capacity - $ds.Summary.FreeSpace
    }
    Select-Object -InputObject $_ -Property @{N='vCenter';E={([uri]$_.ServiceUri).Host}},
        @{N='CpuCapacityGhz';E={[math]::Round($totalCPu/1000,2)}},
        @{N='CpuUsedGhz';E={[math]::Round($usedCPu/1000,2)}},
        @{N='MemCapacityGB';E={[math]::Round($totalMem/1GB,2)}},
        @{N='MemUsedGB';E={[math]::Round($usedMem/1KB,2)}},
        @{N='StorageCapacityTB';E={[math]::Round($totalStor/1TB,2)}},
        @{N='StorageUsedTB';E={[math]::Round($usedStor/1TB,2)}}
}


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

View solution in original post

2 Replies
LucD
Leadership
Leadership
Jump to solution

You could do something like this

ForEach-Object -InputObject $global:DefaultVIServers -Process {
    $totalCPu = $usedCpu = $totalMem = $usedMem = $totalStor = $usedStor = 0
    
    Get-View -ViewType HostSystem -Property 'Summary' -PipelineVariable esx |
    ForEach-Object -Process {
        $totalCpu += $esx.Summary.Hardware.CpuMhz * $esx.Summary.Hardware.numCpuCores
        $usedCpu += $esx.Summary.QuickStats.OverallCpuUsage
        $totalMem += $esx.Summary.Hardware.MemorySize
        $usedMem += $esx.Summary.QuickStats.OverallMemoryUsage
    }
    Get-View -ViewType Datastore -Property 'Summary' -PipelineVariable ds  |
    ForEach-Object -Process {
        $totalStor += $ds.Summary.Capacity
        $usedStor += $ds.Summary.Capacity - $ds.Summary.FreeSpace
    }
    Select-Object -InputObject $_ -Property @{N='vCenter';E={([uri]$_.ServiceUri).Host}},
        @{N='CpuCapacityGhz';E={[math]::Round($totalCPu/1000,2)}},
        @{N='CpuUsedGhz';E={[math]::Round($usedCPu/1000,2)}},
        @{N='MemCapacityGB';E={[math]::Round($totalMem/1GB,2)}},
        @{N='MemUsedGB';E={[math]::Round($usedMem/1KB,2)}},
        @{N='StorageCapacityTB';E={[math]::Round($totalStor/1TB,2)}},
        @{N='StorageUsedTB';E={[math]::Round($usedStor/1TB,2)}}
}


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

Dimon_SPB
Contributor
Contributor
Jump to solution

Thank you so much!

Exactly what is needed!

Reply
0 Kudos