Blog

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="GuestOS";E={$vm.ExtensionData.Config.GuestFullname}},
@{N="DNSName";E={$vm.ExtensionData.Guest.Hostname}},
@{N="VM PowerState";E={$vm.PowerState}},
@{N="Datacenter";E={$vm.Datacenter.name}},
@{N="Cluster";E={$Cluster.Name}},
@{N="Host";E={$vm.VMHost.Name}},
@{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=“Model“;E={$vm.VMHost.Model}},
@{N=“ProcType“;E={$vm.VMHost.ProcessorType}},
@{N="Hard Disk";E={$HardDisk.Name}},
@{N="Datastore";E={$HardDisk.FileName.Split("]")[0].TrimStart("[")}},
@{N="VMConfigFile";E={$VM.ExtensionData.Config.Files.VmPathName}},
@{N="VMDKpath";E={$HardDisk.FileName}},
@{N="VMDK Size";E={($vm.extensiondata.layoutex.file|?{$_.name -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 *