Requirement: Need to gather all the service tags and hardware models of ESXi hosts connected to vCenter.
Script: To be saved as ps1 script and execute it and create temp directory to save the file.
$vcenter = Read-Host "vCenter"
$cred = Get-Credential
Connect-VIServer $vcenter -Credential $cred
$result = Get-VMHost | ForEach-Object {
$h = $_
$esxcli = Get-EsxCli -VMHost $h -V2
try {
$bmc = $esxcli.hardware.ipmi.bmc.get.Invoke()
# Extract IPv4 only
$ipv4 = $bmc.IPv4Address
[PSCustomObject]@{
Host = $h.Name
IPv4Address = $ipv4
}
}
catch {
[PSCustomObject]@{
Host = $h.Name
IPv4Address = "Not Available"
}
}
}
# Export to CSV
$csvPath = "C:\Temp\ESXi_BMC_IPs.csv"
$result | Export-Csv -Path $csvPath -NoTypeInformation
# Optional: also display nicely in console
$result | Format-Table -AutoSize
Write-Host "Report saved to $csvPath"
1) Run the script
2) Prompt will be open for credentials
3) Input the credentials and it will generate the output.
Sample Output:
.png)

Comments
Post a Comment