Skip to content

Instantly share code, notes, and snippets.

@wolruf
Created May 6, 2021 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolruf/cdb60d704366cb1ef75453d78fbc9515 to your computer and use it in GitHub Desktop.
Save wolruf/cdb60d704366cb1ef75453d78fbc9515 to your computer and use it in GitHub Desktop.
vSphere VM reports
$vserver = Read-Host -Prompt 'Enter vCenter Server FQDN or IP address'
$creds = get-credential
Connect-VIServer $vserver -Credential $creds
Get-VM | Select Name, VMHost, NumCpu, MemoryMB, `
@{N="ProvisionedSpace (GB)"; E={[math]::Round($_.ProvisionedSpaceGB)}}, `
@{N="UsedSpace (GB)"; E={[math]::Round($_.UsedSpaceGB)}}, `
@{N="CPU Usage (Average), Mhz" ; E={[Math]::Round((($_ | Get-Stat -Stat cpu.usagemhz.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}}, `
@{N="CPU Usage (Max), MHz" ; E={[Math]::Round((($_ | Get-Stat -Stat cpu.usagemhz.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -Maximum).Maximum),2)}}, `
@{N="MaxHostCpuMhz" ; E={$_.NumCpu * $_.VMHost.CpuTotalMhz / $_.VMHost.NumCpu}}, `
@{N="Memory Usage (Average), %" ; E={[Math]::Round((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}} , `
@{N="Memory Usage (Max), %" ; E={[Math]::Round((($_ | Get-Stat -Stat mem.usage.average -IntervalMins 5 | Measure-Object Value -Maximum).Maximum),2)}} , `
@{N="Network Usage (Average), KBps" ; E={[Math]::Round((($_ | Get-Stat -Stat net.usage.average -Start (Get-Date).AddDays(-30) -IntervalMins 5 | Measure-Object Value -Average).Average),2)}} |`
Export-Csv -Path .\AverageUsage.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment