Practical Linux, Windows Server and cloud guides for IT pros.

VMware PowerCLI Cheat Sheet for vSphere Admins

A practical VMware PowerCLI cheat sheet for vSphere admins, grouped by host checks, VM inventory, snapshots, VMware Tools, storage, networking, and safe destructive actions.

Filed under

,

Published

Written by

Last updated

What is VMware vSphere

This VMware PowerCLI cheat sheet is for vSphere administrators who need quick commands for everyday inventory, reporting, and troubleshooting. The old version of this page was a long numbered list; this version is grouped by task so you can jump straight to the command you need.

Most examples are read-only. Commands that restart services or remove snapshots are clearly labelled because they can affect running environments.

TL;DR

  • Connect to vCenter with Connect-VIServer before running PowerCLI inventory commands.
  • Use the inventory and snapshot report commands first; they are the safest starting point.
  • Review snapshot output before running any Remove-Snapshot command.
  • Restarting hostd or vpxa should be treated as a host-management action, not a casual one-liner.

Source check – 1 June 2026: Broadcom’s VMware PowerCLI reference documents Connect-VIServer for connecting to vCenter and Get-VM for retrieving virtual machines. Always test these commands against a non-production vCenter or a limited scope before running broad queries.

Command Index

TaskCommand familySafetyJump
Connect to vCenterConnect-VIServerLogin/sessionGo
Restart ESXi management agentshostd, vpxaDisruptiveGo
Check CBTExtensionData.ConfigRead-onlyGo
Find E1000 adaptersGet-NetworkAdapterRead-onlyGo
List VM IPsGuest.IPAddressRead-onlyGo
Map VMs to clusters, hosts, and datastoresGet-VM, Get-DatastoreRead-onlyGo
Find old snapshotsGet-SnapshotRead-onlyGo
Remove old snapshotsRemove-SnapshotDestructiveGo
Check VMware ToolsGet-ViewRead-onlyGo
Host CPU and hardware reportsGet-VMHost, Get-ViewRead-onlyGo
VM disk and free-space reportsGet-HardDisk, guest disk dataRead-onlyGo
Find recently created VMsGet-VIEventRead-onlyGo

Before You Run PowerCLI Commands

  • Scope first: Prefer -Name, -Location, -VMHost, or a specific cluster before running against all VMs.
  • Review destructive output: Never pipe snapshot results straight into removal until you have reviewed the exact list.
  • Watch object properties: PowerCLI objects expose nested properties through ExtensionData. These are useful but can vary by object state.
  • Disconnect when finished: Use Disconnect-VIServer when your session is no longer needed.

Connection and Host Actions

Connect to vCenter

Safety: Login/session. Use when: Starting a PowerCLI session against vCenter.

Connect-VIServer -Server 'vcenter.example.com'
How it works

This establishes a PowerCLI session. Use a credential object or your organisation’s approved authentication method instead of hard-coding passwords.

Restart ESXi Management Agents

Safety: Potentially disruptive. Use when: Host management agents are stuck and you have confirmed the operational impact.

/etc/init.d/hostd restart
/etc/init.d/vpxa restart
esxcli system services.sh restart
How it works

hostd and vpxa are part of the ESXi management layer. Restarting them can interrupt host management visibility, so avoid doing this during active troubleshooting unless you know why it is needed.

VM Inventory

Check Whether Change Block Tracking Is Enabled

Safety: Read-only. Use when: Auditing backup-related VM settings.

Get-VM |
    Where-Object { $_.ExtensionData.Config.ChangeTrackingEnabled -eq $true } |
    Select-Object Name
How it works

The command reads each VM’s configuration object and returns the VMs where CBT is enabled.

List VM IP Addresses

Safety: Read-only. Use when: Building a quick guest IP inventory. VMware Tools must be working for good guest data.

Get-VM |
    Select-Object Name, @{Name='IPAddress';Expression={$_.Guest.IPAddress -join ', '}}
How it works

Guest.IPAddress can contain multiple addresses. Joining them prevents arrays from displaying poorly in reports.

Map VMs to Cluster, Host, and Datastore

Safety: Read-only. Use when: Checking where VMs live across clusters, ESXi hosts, and datastores.

Get-VM |
    Select-Object Name,
        @{Name='Cluster';Expression={$_.VMHost.Parent.Name}},
        @{Name='ESXHost';Expression={$_.VMHost.Name}},
        @{Name='Datastore';Expression={($_.DatastoreIdList | Get-Datastore) -join ', '}} |
    Sort-Object Datastore, Name
How it works

This combines VM, host, cluster, and datastore data into one report. It is useful before migrations, datastore maintenance, or capacity reviews.

Find VMs Created Recently

Safety: Read-only. Use when: Auditing recent VM creation, cloning, or deployment events.

Get-VIEvent -Start (Get-Date).AddDays(-10) -MaxSamples ([int]::MaxValue) |
    Where-Object { $_.GetType().Name -in 'VmCreatedEvent','VmBeingClonedEvent','VmBeingDeployedEvent' } |
    Select-Object CreatedTime, UserName, FullFormattedMessage |
    Sort-Object CreatedTime
How it works

The command searches vCenter events from the last 10 days and keeps VM creation, clone, and deployment events.

Network and Storage Inventory

Find VMs Using E1000 Network Adapters

Safety: Read-only. Use when: Finding older virtual NIC types that may need review.

Get-VM |
    Get-NetworkAdapter |
    Where-Object { $_.Type -eq 'E1000' } |
    Select-Object @{Name='VM';Expression={$_.Parent.Name}}, Name, Type, NetworkName
How it works

This reads every VM network adapter and filters for E1000 adapters. Many environments prefer VMXNET3 for modern workloads, but validate guest OS and application requirements before changing adapter types.

List VM Network Adapter Information

Safety: Read-only. Use when: Reporting VM adapter type, network, and connection state.

$vm = Get-VM -Name 'Your_VM_Name'
$vm | Get-NetworkAdapter |
    Select-Object @{Name='VM';Expression={$_.Parent.Name}}, Name, Type, NetworkName, ConnectionState
How it works

Scope the query to one VM while testing. Remove the first line and pipe all VMs into Get-NetworkAdapter only when you want a broader report.

List VM Disk Type and Capacity

Safety: Read-only. Use when: Reporting VMDK capacity and storage format.

Get-VM |
    Get-HardDisk |
    Select-Object @{Name='VM';Expression={$_.Parent.Name}}, Name, StorageFormat,
        @{Name='CapacityGB';Expression={[math]::Round($_.CapacityKB / 1MB, 1)}}
How it works

Get-HardDisk returns virtual disk objects. The calculated property converts PowerCLI’s KB value into GB.

Report Guest Disk Free Space

Safety: Read-only. Use when: Checking guest disk capacity from VMware Tools data.

Get-VM | ForEach-Object {
    $vm = $_
    $vm.ExtensionData.Guest.Disk | Select-Object 
        @{Name='VM';Expression={$vm.Name}},
        DiskPath,
        @{Name='CapacityGB';Expression={[math]::Round($_.Capacity / 1GB, 2)}},
        @{Name='FreeGB';Expression={[math]::Round($_.FreeSpace / 1GB, 2)}}
}
How it works

This depends on guest information from VMware Tools. Missing or stale guest data usually means Tools is not running or the guest has not reported current disk details.

Snapshots and VMware Tools

Find Snapshots Older Than 90 Days

Safety: Read-only. Use when: Auditing old snapshots before cleanup.

Get-VM |
    Get-Snapshot |
    Where-Object { $_.Created -lt (Get-Date).AddDays(-90) } |
    Select-Object VM, Name, Created, @{Name='SizeGB';Expression={[math]::Round($_.SizeMB / 1024, 2)}}
How it works

This finds snapshots older than 90 days and converts size from MB to GB for a cleaner report.

Remove Old Snapshots After Review

Safety: Destructive. Use when: You have already reviewed the exact snapshot list and have approval to remove them.

# Step 1: review first
$oldSnapshots = Get-VM | Get-Snapshot | Where-Object { $_.Created -lt (Get-Date).AddDays(-120) }
$oldSnapshots | Select-Object VM, Name, Created, @{Name='SizeGB';Expression={[math]::Round($_.SizeMB / 1024, 2)}}

# Step 2: remove only after review
$oldSnapshots | Remove-Snapshot -Confirm:$true
How it works

The two-step pattern prevents accidental deletion. Keep -Confirm:$true unless you are running a controlled, reviewed cleanup process.

Count Snapshots Per VM

Safety: Read-only. Use when: Finding VMs with snapshot sprawl.

Get-VM |
    Select-Object Name, @{Name='SnapshotCount';Expression={$_.Snapshot.Count}} |
    Where-Object { $_.SnapshotCount -gt 0 } |
    Sort-Object SnapshotCount -Descending

Get VMware Tools Version

Safety: Read-only. Use when: Auditing guest tools versions.

Get-View -ViewType VirtualMachine -Property Name, Config.Tools.ToolsVersion |
    Select-Object Name, @{Name='ToolsVersion';Expression={$_.Config.Tools.ToolsVersion}}

Host Reports

Get Current Time from ESXi Hosts

Safety: Read-only. Use when: Checking host time drift or NTP troubleshooting symptoms.

Get-VMHost |
    Select-Object Name, @{Name='HostTime';Expression={(Get-View $_.ExtensionData.ConfigManager.DateTimeSystem).QueryDateTime()}}

Get Host CPU and Hardware Information

Safety: Read-only. Use when: Producing a quick host hardware report.

Get-View -ViewType HostSystem -Property Name, Hardware.CpuPkg |
    Select-Object Name, @{Name='CPU';Expression={$_.Hardware.CpuPkg[0].Description}}
Get-VMHost | Sort-Object Name | Get-View |
    Select-Object Name,
        @{Name='Type';Expression={$_.Hardware.SystemInfo.Vendor + ' ' + $_.Hardware.SystemInfo.Model}},
        @{Name='CPUPackages';Expression={$_.Hardware.CpuInfo.NumCpuPackages}},
        @{Name='CPUCores';Expression={$_.Hardware.CpuInfo.NumCpuCores}},
        @{Name='MemoryGB';Expression={[math]::Round($_.Hardware.MemorySize / 1GB, 2)}}

Count VMs Running on Each Host

Safety: Read-only. Use when: Checking VM distribution across hosts.

Get-VMHost |
    Select-Object @{Name='Cluster';Expression={$_.Parent.Name}}, Name, @{Name='VMCount';Expression={$_.ExtensionData.Vm.Count}} |
    Sort-Object Cluster, Name

Related TurboGeek Guides

Final Notes

PowerCLI one-liners are best used as repeatable report starters. Once a command becomes part of regular operations, turn it into a script with parameters, logging, error handling, and change-control notes.

Leave a Reply

Your email address will not be published. Required fields are marked *

Find more on the site

Keep reading by topic.

If this post was useful, the fastest way to keep going is to pick the topic you work in most often.

Want another useful post?

Browse the latest posts, or support TurboGeek if the site saves you time regularly.

Translate ยป