Site icon Digital Thought Disruption

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 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:


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
Exit mobile version