← script library

Retrieve VM Information in VMware vSphere

VMware & vSphereJanuary 8, 2025

This post details a PowerShell script designed to retrieve and display vital information about virtual machines (VMs) in a VMware vSphere environment. By automating this process, you can easily monitor VM configurations and performance.

powershell
# Define vCenter Server details
$vcServer = "vcenter_server_IP_or_FQDN"
$vcUser = "username"
$vcPassword = "password"
# Connect to the vCenter Server
Connect-VIServer -Server $vcServer -User $vcUser -Password $vcPassword

# Retrieve all virtual machines
$vms = Get-VM

# Display information for each VM
foreach ($vm in $vms) {
    Write-Host "VM Name: $($vm.Name)"
    Write-Host "Power State: $($vm.PowerState)"
    Write-Host "CPU Count: $($vm.NumCpu)"
    Write-Host "Memory Size (MB): $($vm.MemoryMB)"
    Write-Host "-------------------------------------"
}

# Disconnect from the vCenter Server
Disconnect-VIServer -Server $vcServer -Confirm:$false

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.