VMware Cloud Community
Jimleslie1977
Contributor
Contributor

Powercli export list to CSV containing specific host info

I would like to run a powercli script to gather the below info

 

Hostname | Version | Build | Model | Number of CPUs | Current License Key Used 

 

I have been playing around with this but doesnt seem to list all my hosts.  We do have some in atacenters and clusters within those, I think Im missing a bit to recursivlet seek through these DC's and Clusters, any ideas would be welcomed, and thanks

 

$VC = @("vcname")
Connect-VIServer -Server $VC -user username" -Password Password
{
$HostReport = @()

Get-VMHost |Get-View |%{

$Report = "" | select Hostname, version, Build, manufacture, Model,cpu_model, cpu_num, core_num, ip_address,vmotion_ip, HBA_num, P_nic

$Report.Hostname = $_.Name

$Report.version =$_.Config.Product.Version

$Report.Build =$_.Config.Product.Build

$Report.manufacture =$_.Hardware.SystemInfo.Vendor

$Report.Model =$_.Hardware.SystemInfo.Model

$Report.cpu_model =$_.Summary.Hardware.CpuModel

$Report.cpu_num =$_.Hardware.CpuInfo.NumCpuPackages

$Report.core_num =$_.Hardware.CpuInfo.NumCpuCores

if($Report.version -like "3.5.*"){

$Report.ip_address =$_.Config.Network.ConsoleVnic.Spec.ip.ipaddress

}

else {$Report.ip_address =$_.Config.Network.ConsoleVnic[0].Spec.ip.ipaddress}

$Report.vmotion_ip =$_.Config.Vmotion.IpConfig.IpAddress

$Report.HBA_num =$_.Summary.Hardware.NumHBAs

$Report.P_nic =$_.Config.Network.Pnic.count

$HostReport += $Report

}

}

$HostReport | Export-Csv "C:\Support\VMWare\Reports\37Full-HostReport.csv" –NoTypeInformation

0 Kudos
1 Reply
LucD
Leadership
Leadership

I wonder how you got anything in your report.
You placed the bulk of your lines in a code block, that will execute nothing.

Try like this

$VC = @("vcname")
Connect-VIServer -Server $VC -User "username" -Password Password

$HostReport = @()

Get-VMHost | Get-View | % {
    $Report = "" | select Hostname, version, Build, manufacture, Model, cpu_model, cpu_num, core_num, ip_address, vmotion_ip, HBA_num, P_nic
    $Report.Hostname = $_.Name
    $Report.version = $_.Config.Product.Version
    $Report.Build = $_.Config.Product.Build
    $Report.manufacture = $_.Hardware.SystemInfo.Vendor
    $Report.Model = $_.Hardware.SystemInfo.Model
    $Report.cpu_model = $_.Summary.Hardware.CpuModel
    $Report.cpu_num = $_.Hardware.CpuInfo.NumCpuPackages
    $Report.core_num = $_.Hardware.CpuInfo.NumCpuCores
    if ($Report.version -like "3.5.*") {
        $Report.ip_address = $_.Config.Network.ConsoleVnic.Spec.ip.ipaddress
    } else { 
        $Report.ip_address = $_.Config.Network.ConsoleVnic[0].Spec.ip.ipaddress 
    }
    $Report.vmotion_ip = $_.Config.Vmotion.IpConfig.IpAddress
    $Report.HBA_num = $_.Summary.Hardware.NumHBAs
    $Report.P_nic = $_.Config.Network.Pnic.count

    $HostReport += $Report
}

$HostReport | Export-Csv "C:\Support\VMWare\Reports\37Full-HostReport.csv" -NoTypeInformation


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

0 Kudos