So a script that gives me vCenter version and build, host version and build and all VMs with version of VMTools if possible. Many thanks
Original Message:
Sent: Feb 04, 2025 05:07 AM
From: Ph Sp
Subject: Get vCenter and ESXi Host Version and Build numbers
Yes, i have got it now. First i run Connect-VIServer -Server ipaddress -Protocol https -User -Password | Select * then i run
Connect-VIServer -Server ipaddress -Protocol https -User -Password | ForEach-Object -Process {
$vc = $_
Get-VMHost -Server $vc |
ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
vCenter = $vc.Name
vCenterVersion = $vc.Version
vCenterBuild = $vc.Build
VMHost = $_.Name
VMHostVersion = $_.Version
VMHostBuild = $_.Build
})
}
} | Export-Csv -Path .\filename.csv -NoTypeInformation -UseCulture
This then gives me the vCenter version and build.
Also, if i want to get all VMs into the csv too, please could you add to the script the commands to do this.
Thanks for all of your help with this. It is very much appreciated.
Original Message:
Sent: Feb 04, 2025 04:51 AM
From: LucD
Subject: Get vCenter and ESXi Host Version and Build numbers
It must be how you run the code from the prompt.
How do you run the code I provided?
Do you run that script from the prompt?
Normally you save such scripts in a .ps1 file and run from there.
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Original Message:
Sent: Feb 04, 2025 04:39 AM
From: Ph Sp
Subject: Get vCenter and ESXi Host Version and Build numbers
I get this when running
Connect-VIServer -Server ip address -Protocol https -User username -Password pass |Select *

Displays the vCenter Version and Build but not in the csv
Original Message:
Sent: Feb 03, 2025 10:57 AM
From: LucD
Subject: Get vCenter and ESXi Host Version and Build numbers
Works for me.
Check what object, with which properties, the Connect-VIServer cmdlet returns
Connect-VIServer -Server ip address -Protocol https -User username -Password pass |Select *
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Original Message:
Sent: Feb 03, 2025 09:50 AM
From: Ph Sp
Subject: Get vCenter and ESXi Host Version and Build numbers
Thanks again LucD
It appears to be missing the vCenter Appliance info in the csv, but host and other info is correct. Any ideas please?

Original Message:
Sent: Feb 03, 2025 06:23 AM
From: Ph Sp
Subject: Get vCenter and ESXi Host Version and Build numbers
Thanks LucD, much appreciated.
I only need to log into one vCenter at a time so would this do the trick:
PowerCLI C:\> Connect-VIServer -Server ip address -Protocol https -User username -Password pass | ForEach-Object -Process {
$vc = $_
Get-VMHost -Server $vc |
ForEach-Object -Process {
New-Object -TypeName PSObject -Property ([ordered]@{
vCenter = $vc.Name
vCenterVersion = $vc.Version
vCenterBuild = $vc.Build
VMHost = $_.Name
VMHostVersion = $_.Version
VMHostBuild = $_.Build
})
}
} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
Original Message:
Sent: Feb 03, 2025 05:28 AM
From: LucD
Subject: Get vCenter and ESXi Host Version and Build numbers
Try something like this
$global:defaultVIServers | ForEach-Object -Process { $vc = $_ Get-VMHost -Server $vc | ForEach-Object -Process { New-Object -TypeName PSObject -Property ([ordered]@{ vCenter = $vc.Name vCenterVersion = $vc.Version vCenterBuild = $vc.Build VMHost = $_.Name VMHostVersion = $_.Version VMHostBuild = $_.Build }) }} | Export-Csv -Path .\report.csv -NoTypeInformation -UseCulture
------------------------------
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Original Message:
Sent: Feb 03, 2025 03:59 AM
From: Ph Sp
Subject: Get vCenter and ESXi Host Version and Build numbers
I need to extract vCenter and ESXi host versions and builds using PowerCLI (or PowerShell if possible) then output to a csv or a table to save and add to a master spreadsheet. Apologies, i am new to PowerCLI and need help to achieve this. I would be grateful if anybody could provide me with a script to achieve this. Many thanks
------------------------------
PS
------------------------------