PowerCLI for Beginners: The Complete 2025 Getting Started Guide

Introduction

PowerCLI is the official command-line toolkit from VMware. It extends PowerShell with over 700 cmdlets to manage vSphere, vCenter, ESXi, vSAN, NSX, and more. If you are new to VMware automation, PowerCLI is your entry point.

This beginner’s guide covers:

  • What PowerCLI is and why it matters
  • How to install it on any platform
  • How to connect to vCenter
  • Core PowerCLI cmdlets you’ll use daily
  • Sample scripts to get started

What is PowerCLI?

PowerCLI is a set of VMware modules for PowerShell that allow you to automate and script nearly everything in your virtual environment.

Common uses:

  • Manage VMs and hosts
  • Export inventory reports
  • Automate deployments and backups
  • Validate compliance and configuration

Step 1: Install PowerShell (if not already installed)

Windows:

PowerShell is built-in. Update to PowerShell 7+ from https://github.com/powershell/powershell

macOS / Linux:

Use Homebrew or apt:

brew install --cask powershell
sudo apt install powershell

Launch with:

pwsh

Step 2: Install PowerCLI

Inside PowerShell:

Install-Module -Name VMware.PowerCLI -Scope CurrentUser

Accept the untrusted repo prompt with Y.

Verify install:

Get-Module -Name VMware.PowerCLI -ListAvailable

Step 3: Connect to vCenter

Connect-VIServer -Server "vcenter.lab.local" -User "admin@lab.local" -Password "YourPassword"

Store credentials securely:

New-VICredentialStoreItem -Host "vcenter.lab.local" -User "admin@lab.local" -Password "YourPassword"

Step 4: Your First PowerCLI Commands

Get-VM                         # List all virtual machines
Get-VMHost # List ESXi hosts
Get-Datastore # Show storage
Get-Cluster # Show clusters
Get-VM | Where PowerState -eq "PoweredOff"

Diagram: PowerCLI First Steps


Step 5: Export VM Report to CSV

Get-VM | Select Name, PowerState, VMHost | Export-Csv "C:\Reports\VMs.csv" -NoTypeInformation

Step 6: Shutdown a VM Gracefully

Stop-VMGuest -VM "WebApp01" -Confirm:$false

Step 7: Create a Snapshot

New-Snapshot -VM "SQLServer01" -Name "BeforePatch" -Description "Patch prep"

Bonus: Build Your First Script

Save the following in C:\Scripts\DailyVMReport.ps1

Connect-VIServer -Server "vcenter.lab.local"
Get-VM | Select Name, PowerState, VMHost | Export-Csv "C:\Reports\VMReport.csv" -NoTypeInformation
Disconnect-VIServer * -Confirm:$false

Run it from PowerShell:

powershell.exe -File "C:\Scripts\DailyVMReport.ps1"

Troubleshooting for Beginners

IssueSolution
Command not recognizedRun Import-Module VMware.PowerCLI to reload module
Certificate errors on connectRun Set-PowerCLIConfiguration -InvalidCertificateAction Ignore
Permission deniedUse Run as Administrator and confirm role access in vCenter
No output from Get-VMEnsure connection to the correct vCenter and no filters applied

Leave a Reply

Discover more from Digital Thought Disruption

Subscribe now to keep reading and get access to the full archive.

Continue reading