Zoznam VMs, ktore niesu vo vCenter

Kedže nie všetky esx hosty musia byť nutne vo vCenter (z rôznych prevádzkových dôvodov), po určitom čase už nemusite mať aktuálne info o VMs ktoré na nich bežia. Preto môže pomocť script aj pre zoznam VMs na týchto hostoch.

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\ListLinuxEsxiVMs{0:yyyyMMdd}.csv" -f (Get-Date)
$VMs = Get-VM -Server $ESXiHosts.IP
$VMs | %{
 
 $ResolveDNS = Resolve-DnsName -Server 10.10.10.100 -Name $_.VMhost -ErrorAction SilentlyContinue | Select-Object -ExpandProperty NameHost -First 1
 $row = "" | Select "VM Name", "HW Version", State, IP, Memory, OS, "Resource Pool", Notes, NumCpu, Folder, Host, HostDNS

 $Ver = $_|get-view
 $vmGuest = $_ | Get-VMGuest
 $row."VM Name" = $_.Name
 $row."HW Version"= $Ver.Config.Version
 $row.State = $_.PowerState
 $row.IP=$vmGuest.IPAddress[0]
 $row.Memory=$_.MemoryMB
 $row.OS=$vmGuest.OSFullName
 $row."Resource Pool"=$_.ResourcePool
 $row.Notes=$_.Notes
 $row.NumCpu=$_.NumCpu
 $row.Folder=$_.Folder
 $row.Host=$_.VMHost
 $row.HostDNS=$ResolveDNS 
 $report += $row

}

$report | Export-CSV $filename1 -NoTypeInformation

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