Close Menu
  • News
  • VMware
  • Windows
  • Linux
  • DevOps
  • Contact
LinkedIn Facebook X (Twitter) Instagram
TechnicalTerm.com
  • News
  • VMware
  • Windows
  • Linux
  • DevOps
  • Contact
Facebook X (Twitter) Instagram
TechnicalTerm.com
Home»VMware»Get VM Info from vCenter Using PowerCLI – The easy way
VMware

Get VM Info from vCenter Using PowerCLI – The easy way

A PowerShell script to list CPU, RAM, PowerState and Cores per Socket of all VMs in vCenter
Catalin CristescuBy Catalin CristescuFebruary 18, 2025152 Views
LinkedIn Twitter Facebook Copy Link Email WhatsApp
VMware PowerCLI Script for VM Monitoring – Automate vCenter Management with PowerShell
LinkedIn Twitter Facebook Copy Link

If you work with VMware, you know how annoying it can be to click through the vSphere UI just to check some basic VM details. That’s where PowerCLI comes in handy. With a few lines of PowerShell, you can quickly pull up CPU, RAM, and power state info for all your VMs. In this post, I’ll show you a script that connects to vCenter, grabs VM details, and logs out – all in one go.

Prerequisites

Before running this script, make sure you have:

  • VMware PowerCLI installed.
  • Proper credentials to access your vCenter Server.
  • PowerShell script execution enabled.

The PowerShell Script

Here’s a quick script to fetch details of all VMs in vCenter:

# Import VMware PowerCLI module
Import-Module VMware.PowerCLI
Import-Module -Name VMware.VimAutomation.Core -ErrorAction SilentlyContinue
Set-PowerCLIConfiguration -ProxyPolicy NoProxy -DefaultVIServerMode multiple -Scope User -InvalidCertificateAction ignore -Confirm:$false | Out-Null

# Define vCenter Server and credentials
$vCenterServer = "your-vcenter-server"
$username = "administrator@vsphere.local"
$password = "your-password"

# Connect to vCenter Server
Connect-VIServer -Server $vCenterServer -User $username -Password $password

# Get all VMs from vCenter
$vms = Get-VM

# Loop through each VM and retrieve its configuration
foreach ($vm in $vms) {
    if ($vm) {
        # Get CPU and RAM configuration
        $cpuCount = $vm.NumCpu
        $ramGB = $vm.MemoryGB
        $coresPerSocket = $vm.ExtensionData.Config.Hardware.NumCoresPerSocket
        $socketCount = $cpuCount / $coresPerSocket
        $autoCorePerSocket = $vm.ExtensionData.Config.Hardware.AutoCoresPerSocket
        $powerState = $vm.PowerState

        # Output the details
        Write-Host "VM Name: $($vm.Name)"
        Write-Host "Power State: $powerState"
        Write-Host "CPU Count: $cpuCount"
        Write-Host "RAM: $ramGB GB"
        Write-Host "Cores per Socket: $coresPerSocket"
        Write-Host "Socket Count: $socketCount"
        Write-Host "Auto Core Per Socket: $autoCorePerSocket"
        Write-Host "----------------------------------------"
    }
}

# Disconnect from vCenter Server
Disconnect-VIServer -Server $vCenterServer -Confirm:$false

What this script does

  1. Loads PowerCLI modules: Ensures all necessary VMware cmdlets are available.
  2. Logs into vCenter: Connects using provided credentials.
  3. Gets all VMs: No need to specify names manually.
  4. Loops through each VM: Retrieves CPU, RAM, and power state.
  5. Prints results: Displays everything in the console.
  6. Logs out: Closes the session to keep things clean.

Why use this script?

  • No more clicking through vSphere UI: Get all VM details instantly.
  • Scales easily: Works for any number of VMs.
  • Saves time: Run once and get everything you need.

Final thoughts

This script is a must-have for any VMware engineer who wants a fast and easy way to check VM configurations. Whether you’re troubleshooting, auditing, or just curious about your VM resources, PowerCLI makes it simple. Try it out and let me know if you have any improvements! 🚀

PowerCLI Powershell Virtualization VMware vSphere
Next Article Automate HPE iLO Certificate Signing Requests with PowerShell
Catalin Cristescu
  • Website
  • X (Twitter)
  • LinkedIn

I’m the founder of TechnicalTerm.com and a Wintel & Virtualization Consultant with more than seven years of hands-on experience. I’ve served as a Wintel & Virtualization Consultant and DevOps professional. Along the way, I’ve managed multiple VMware vSphere environments, handled Windows OS support, and implemented automated provisioning processes using VMware Aria solutions like vRA and vRO. My dedication to virtualization earned me the vExpert award and VMware Certified Implementation Expert – Data Center Virtualization certification, reflecting my passion for streamlining data centers and IT operations.

Related Posts

VMSA-2025-0004: Critical VMware Vulnerabilities: Why You Should Patch Right Away

March 4, 2025

VMware vExpert 2025 Statistics

February 27, 2025

Top 5 VMware vCenter events to watch for a healthy virtual environment

February 23, 2025
Leave A Reply Cancel Reply

Recent Posts
  • VMSA-2025-0004: Critical VMware Vulnerabilities: Why You Should Patch Right Away
  • VMware vExpert 2025 Statistics
  • Top 5 VMware vCenter events to watch for a healthy virtual environment
  • Automate HPE iLO Certificate Signing Requests with PowerShell
  • Get VM Info from vCenter Using PowerCLI – The easy way
Facebook X (Twitter) Instagram Pinterest
  • About
  • Contact
  • Privacy Policy
  • Cookie Policy
© 2025 TechnicalTerm>_

Type above and press Enter to search. Press Esc to cancel.