вторник, 21 февраля 2023 г.

Extract ESXi iDrac and BIOS versions and their IPs with PowerCLI

 cls

$viserver = "vCenter"

$User = "USER"

$Pass = "PASSWORD"

Disconnect-VIServer * -Confirm:$false -ErrorAction SilentlyContinue | Out-Null

$UnsortedVMHosts = (Get-VMHost).name

$VMHostNames = $UnsortedVMHosts | sort #  | select -First 3

$Array = @()

Write-Host


foreach($ESXiName in $VMHostNames)

    {

    Connect-VIServer -Server $viserver -User $User -Password $Pass

    $OneLineArray = New-Object "PSCustomObject"

    

    $ESXiName

    $VMHost = Get-VMHost $ESXiName

    $VMView = $VMHost | Get-View

    $BiosInfo = $VMView.Hardware.BiosInfo

        

    $Vendor = $VMHost.ExtensionData.Hardware.SystemInfo.Vendor

    $Model = $VMHost.ExtensionData.Hardware.SystemInfo.Model

    $BiosVersion = $BiosInfo.BiosVersion

    $ReleaseDate = $BiosInfo.ReleaseDate

    $EsxIP = (Get-VMHostNetworkAdapter -VMHost $VMHost -VMKernel -Name vmk0).IP

    $EsxiVer = $VMHost.ExtensionData.Config.Product.FullName

    $vCenter = $VMHost.ExtensionData.Client.ServiceContent.About.FullName


    Disconnect-VIServer * -Confirm:$false -ErrorAction SilentlyContinue

    Connect-VIServer -Server $ESXiName -User root -Password "PASSWORD" # | Out-Null

    Connect-VIServer -Server $ESXiName -User Administrator -Password "PASSWORD" # | Out-Null

    $esxcli = Get-EsxCli -VMHost $ESXiName -V2

    $iDracIP = $esxcli.hardware.ipmi.bmc.get.Invoke().IPv4Address

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "ESXiName" -Value $ESXiName

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "Vendor" -Value $Vendor

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "Model" -Value $Model

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "BiosVersion" -Value $BiosVersion

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "ReleaseDate" -Value $ReleaseDate

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "EsxIP" -Value $EsxIP

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "iDracIP" -Value $iDracIP

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "EsxiVer" -Value $EsxiVer

    $OneLineArray | Add-Member -MemberType NoteProperty -Name "vCenter" -Value $vCenter

    $Array += $OneLineArray

    }

$Array | OGV -Title "ESXi Hosts"

$Array | Export-Csv "C:\Temp\ESXiHosts-report.csv" -NoTypeInformation -UseCulture

ii "C:\Temp\report.csv"

    

Комментариев нет:

Отправить комментарий