Zoznam ESX hostov, ktoré niesú vo vCenter

Kedže môžete mať pár ESX hostov, ktoré niesú vo vCenter, vytvoril som script ktorý vám po spustení vytvorí csv s informáciami ako sú DNS záznam,počet vCPU alebo velkost voľného diskového pristoru na lokálnych datastoreoch. Môže sa hodiť.

add-pssnapin VMware.VimAutomation.Core
$ESXiHosts = Import-Csv "C:\Scripts\Import\ServersLinuxESXi.txt"

$username = "root"
$password = Get-Content "C:\Scripts\MartinESXiRootPassword.txt" | ConvertTo-SecureString
$cred = new-object -typename System.Management.Automation.PSCredential `
 -argumentlist $username, $password

connect-VIserver -server $ESXiHosts[0].IP,$ESXiHosts[1].IP,$ESXiHosts[2].IP,$ESXiHosts[3].IP -Credential $cred
$report = @()

$filename1="C:\Scripts\Exports\ListLinuxEsxiHosts{0:yyyyMMdd}.csv" -f (Get-Date)
$ESXiHosts1 = Get-VMHost 
$ESXiHosts1 | ForEach-Object {
                      $ResolveDNS = Resolve-DnsName -Server 10.10.10.100 -Name $_ -ErrorAction SilentlyContinue | Select-Object -ExpandProperty NameHost -First 1
                      $row = "" | Select-Object "Host Name", "DNS Host Name","Version", PowerState, Memory, NumCpu, DatastoreTotal, DatastoreFree, LicenseKey

                      $Datastore = $_ | Get-Datastore
                      $row."Host Name" = $_.Name
                      $row."DNS Host Name"=$ResolveDNS
                      $row."Version"= $_.Version
                      $row.PowerState = $_.PowerState
                      $row.Memory=$_.MemoryTotalGB
                      $row.NumCpu=$_.NumCpu
                      $row.DatastoreTotal=$Datastore.CapacityGB
                      $row.DatastoreFree=$Datastore.FreeSpaceGB
                      $row.LicenseKey=$_.LicenseKey 
                      $report += $row
                      }

$report | Export-CSV $filename1 -NoTypeInformation
send-mailmessage -from "VCenter <vc@yourcompany.com>" -to "vy@yourcompany.com <vy@yourcompany.com>" -subject "Reports from ESXi hosts" -body "List of VMs on ESXi hosts" -Attachments "$filename1" -smtpServer smtp.yourcompany.com<

Author: Martin

Infrastructure engineer | virtualization & cloud enthusiast | vSphere specialist | blogger | Veeam Vanguard 2021,2022,2023 | VMware vExpert 2017 - 2024 | VMCE | VCP-DCV, NV, TKO, VCAP-DCV | Slovak VMUG Leader | Slovak VUG Leader | husband&father