Powercli script to get host information

This is a very useful script to get ESXi information and out output the information to use for what ever, you can play with the commands add and remove what ever is relevant.

best way to see what other options there are is to create a vm variable for a test vm and the run the extension dot “.” commands against $vm the results should show you what to add etc.

Here we have

Host CPU hardware information and core count etc

VM disk and config information with datastore info etc..

$VmInfo = ForEach ($Datacenter in (Get-Datacenter | Sort-Object -Property Name)) {
ForEach ($Cluster in ($Datacenter | Get-Cluster | Sort-Object -Property Name)) {
ForEach ($VM in ($Cluster | Get-VM | Sort-Object -Property Name)) {
ForEach ($HardDisk in ($VM | Get-HardDisk | Sort-Object -Property Name)) {
"" | Select-Object -Property @{N="VM";E={$VM.Name}},
@{N="VM CPU#";E={$vm.ExtensionData.Config.Hardware.NumCPU/$vm.ExtensionData.Config.Hardware.NumCoresPerSocket}},
@{N="VM CPU Core#";E={$vm.NumCPU}},
@{N="VM PowerState";E={$vm.PowerState}},
@{N="Host CPU#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
@{N="Host CPU Core#";E={$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuCores/$vm.VMHost.ExtensionData.Summary.Hardware.NumCpuPkgs}},
@{N="Hard Disk";E={$HardDisk.Name}},
@{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$ -contains $harddisk.filename.replace(".","-flat.")}).size/1GB}},
@{N="Drive Size";E={$HardDisk.CapacityGB}}
$VmInfo | Export-Csv -NoTypeInformation -UseCulture -Path "c:\scripts\reports\report_VCT03.csv"


Leave a Comment

Your email address will not be published. Required fields are marked *