Skip to content

Instantly share code, notes, and snippets.

@biacz
Last active March 15, 2019 10:39
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 biacz/e04be1b46c679ebe805a5bf9928f6f31 to your computer and use it in GitHub Desktop.
Save biacz/e04be1b46c679ebe805a5bf9928f6f31 to your computer and use it in GitHub Desktop.
Connect-VIServer asdf
Clear-Variable report
$report = Get-Datacenter -PipelineVariable datacenter |
ForEach-Object {
get-cluster -Location $_ -PipelineVariable cluster |
ForEach-Object { get-vmhost -Location $_ |
foreach-object {[pscustomobject]@{
Datacenter=$datacenter.Name;
Cluster=$cluster.Name;
Name=$_.Name;
NumCPU=$_.NumCpu;
MemoryGB=[math]::Round($_.MemoryTotalGB);
MemoryUsedGB=[math]::Round($_.MemoryUsageGB);
CpuTotalMhz=[math]::Round($_.CpuTotalMhz);
CpuUsedMhz=[math]::Round($_.CpuUsageMhz);
MemoryUsedPct=[math]::Round(($_.MemoryUsageGB/$_.MemoryTotalGB*100));
CpuUsedPct=[math]::Round($_.CpuUsageMhz/$_.CpuTotalMhz*100);
NumVMs=$(get-vm -Location $_).count
}
}
}
}
$report | export-csv -Force -NoTypeInformation -path "c:\temp\powerbifeed.csv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment