суббота, 15 сентября 2018 г.

VMWare ESXi Inventory with PowerShell 2

===START===
Connect-VIServer -User administrator@domain.com -Password Ietv2323. vSRV.domain.com

$ALLWMHOSTS = (get-vmhost).name
$output = New-Object System.Collections.ArrayList
foreach ($WMHOST in $AllWMHOSTS) {

    $WMHOST
    $TCFOUND = $true

    Try { Test-Connection -ComputerName $WMHOST -Count 1 -ErrorAction Stop }
    Catch { $TCFOUND = $false }

    IF ($TCFOUND) {
$IPTC = Test-Connection -ComputerName $WMHOST -Count 1 | Select-Object IPV4Address, Address
$PingResult = "UP"
$IPV4 = $IPTC.IPV4Address
$VMHOSTHARDWARE = get-VMHOSTHARDWARE -VMHost $WMHOST | Select-object vmhost, model, manufacturer, serialnumber
$VMHOSTNETWORK = Get-VMHostNetwork -VMHost $WMHOST | select-object VMHost,DomainName, HostName, DnsAddress
$VMHOSTINFO = get-vmhost -Name $WMHOST | SELECT-OBJECT name, networkinfo, model, manufacture, ApiVersion, Version
$thisUUID = (Get-EsxCli -VMHost $WMHOST).system.uuid.get()
$decDate = [Convert]::ToInt32($thisUUID.Split("-")[0], 16)
$installDate = [timezone]::CurrentTimeZone.ToLocalTime(([datetime]'1/1/1970').AddSeconds($decDate))
   
    $OSSystem = "ESX - "+$VMHOSTINFO.model
    $OSServicePack = $VMHOSTINFO.Version
    $OSVer = $VMHOSTINFO.ApiVersion
    $LLStamp = ""
    $dnshostname = $VMHOSTNETWORK.HostName
    $OSDate = $installDate
    $domain = $VMHOSTNETWORK.DomainName
    $domainrole = ""
    $CompVendor = $VMHOSTHARDWARE.manufacturer
    $CompModel = $VMHOSTHARDWARE.model
    $CompSerial = $VMHOSTHARDWARE.serialnumber
    }
    ELSE
   {
    $PingResult = "DOWN"
    $IPV4 = ""
    $OSSystem = "ESX"
    $OSServicePack = ""
    $OSVer = ""
    $LLStamp = ""
    $dnshostname = ""
    $OSDate = ""
    $domain = ""
    $domainrole = ""
    $CompVendor = ""
    $CompModel = ""
    $CompSerial = ""
    }
    $Computerinfo  = New-Object -Type PSObject
    $Computerinfo | Add-Member -MemberType NoteProperty -Name "Name" -Value "$WMHOST" -Force
    $Computerinfo | Add-Member -MemberType NoteProperty -Name "domain" -Value "$domain" -Force
    $Computerinfo | Add-Member -MemberType NoteProperty -Name "OSSystem" -Value "$OSSystem" -Force
    $Computerinfo | Add-Member -MemberType NoteProperty -Name "PingResult" -Value "$PingResult" -Force
    $Computerinfo | Add-Member -MemberType NoteProperty -Name "IPV4" -Value "$IPV4" -Force
    $Computerinfo | Add-Member -MemberType NoteProperty -Name "DNSHostName" -Value "$dnshostname" -Force
    $Computerinfo | Add-Member -MemberType NoteProperty -Name "OSVersion" -Value "$OsVer" -Force
    $Computerinfo | Add-Member -MemberType NoteProperty -Name "OSServicePack" -Value "$OsServicePack" -Force
    $Computerinfo | Add-Member -MemberType NoteProperty -Name "LLStamp" -Value "$LLStamp" -Force
    $Computerinfo | Add-Member -MemberType NoteProperty -Name "Vendor" -Value "$CompVendor" -Force
    $Computerinfo | Add-Member -MemberType NoteProperty -Name "Model" -Value "$CompModel" -Force
    $Computerinfo | Add-Member -MemberType NoteProperty -Name "Serial Number" -Value "$CompSerial" -Force
    $Computerinfo | Add-Member -MemberType NoteProperty -Name "OSDate" -Value "$OSDate" -Force

    $output.Add($Computerinfo) | Out-Null
    $PingStatusCode = ""
    $PingResult = ""
    $VMHOSTHARDWARE = ""
    $WMHOSTNETADAPTER = ""
    $VMHOSTNETWORK = ""
    $VMHOSTINFO = ""
    $thisUUID = ""
    $decDate = ""
    $installDate = ""
    $OSDate = ""
    }
$output | Export-Csv Z:\D\input-output\output_ESX.csv
Disconnect-VIServer -User administrator@domain.com -Password Ietv2323. vSRV.domain.com
===END===

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

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