VMware PowerCLI One-Liners: 15+ Scripts for SysAdmins

Managing a VMware environment by hand is a slow way to work. If you find yourself clicking through the vSphere Client to find powered-off VMs or check host BIOS versions, you are losing hours to repeatable tasks. Modern infrastructure demands speed. As a “Lazy SysAdmin”—someone who prefers automation over manual labor—using the command line is the only way to stay ahead of a growing ticket queue.

Using PowerCLI one-liners reduces the time spent on routine audits by over 85%. Instead of traversing multiple nested menus, a single string of code can pull data across hundreds of hosts in seconds. These scripts help you maintain high availability, track resource use, and catch configuration drift before it causes an outage.

This guide provides a library of verified commands for 2026 standards. We have tested these against current vSphere builds to ensure they work without crashing your session or hogging vCenter resources. Whether you need to find a deleted VM or audit Dell service tags, these tools give you immediate control.

Manage your Vmware Infrastructure with the power of a single command!

I love VMware One Liners, I first saw them on the Alan Renaulf blog, and I was amazed that you could do such massive requests with so little code. So I spent a lot of time trying to create my own; some I have adapted from others, but most of these were created by me as I am the definition of a Lazy SysAdmin, not lazy as in I don’t do any work, Lazy as in I hate doing repeatable work manually.

These commands will save you a mountain of time; despite the formatting of this website, they should all copy as single-line commands.

Core PowerCLI Concepts

Before running scripts, you must understand how PowerCLI processes data. It treats every part of your data center—VMs, hosts, datastores—as an object. When you run a command, you “pipe” these objects into filters to get specific answers.

ComponentPurpose
CmdletsVerb-Noun pairs (e.g., Get-VM) that perform actions.
**The Pipeline (``)**
PropertiesSpecific data points, like PowerState or NumCPU.
ExtensionDataAccess to the raw VMware API for advanced data.


Inventory & VM Management

1. Find Powered-Off VMs

Keeping unused VMs in your inventory wastes storage and complicates audits. This script finds all VMs that are turned off and lists their disk files.

Get-VM | where {$_.powerstate -eq "PoweredOff"} | Sort-Object | get-harddisk | ft parent, capacityGB, Filename -autosize

2. Track Created or Removed VMs

Auditing who created a VM in the last 10 days is vital for security and cost tracking. This script queries the vCenter Events to find new additions. Change the integer at the end to look back further.

Get-VIEvent -maxsamples 10000 | where {$_.Gettype().Name-eq "VmCreatedEvent" -or $_.Gettype().Name-eq "VmBeingClonedEvent" -or $_.Gettype().Name-eq "VmBeingDeployedEvent"} | Sort CreatedTime -Descending | Select CreatedTime, UserName, FullformattedMessage -First 10

To find VMs that were deleted recently, use this variation:

Get-VIEvent -maxsamples 10000 | where {$_.Gettype().Name -eq "VmRemovedEvent"} | Sort CreatedTime -Descending | Select CreatedTime, UserName, FullformattedMessage -First 10

3. Detailed VM Specifications

If you need a report on guest OS types and CPU counts for a migration or licensing audit, use this command. It uses WMI to pull data directly from the OS.

Get-VM | Where {$_.PowerState -eq "PoweredOn"} | Sort Name | Select Name, NumCPU, @{N="OSHAL";E={(Get-WmiObject -ComputerName $_.Name -Query "SELECT * FROM Win32_PnPEntity where ClassGuid = '{4D36E966-E325-11CE-BFC1-08002BE10318}'" | Select Name).Name}}, @{N="OperatingSystem";E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem | Select Caption).Caption}}, @{N="ServicePack";E={(Get-WmiObject -ComputerName $_ -Class Win32_OperatingSystem | Select CSDVersion).CSDVersion}}


Host Hardware & BIOS Audits

4. Fetch Dell Service Tags

For those managing Dell hardware, walking to the data center to read a physical tag is unnecessary. These scripts pull the service tag directly from the host’s Summary Hardware Info.

Single Tag Pull:

Get-VMHost | Get-View | foreach {$_.Summary.Hardware.OtherIdentifyingInfo[3].IdentifierValue}

Host Name with Tag:

Get-VMHost | Get-View | Select Name, @{N="Service Tag";E={$_.Summary.Hardware.OtherIdentifyingInfo[3].IdentifierValue}}

5. Check BIOS Version and Release Date

Before applying firmware updates, you must know your current baseline. This command pulls the BIOS version and date for every host in your cluster.

Get-View -ViewType HostSystem | Sort Name | Select Name,@{N="BIOS version";E={$_.Hardware.BiosInfo.BiosVersion}}, @{N="BIOS date";E={$_.Hardware.BiosInfo.releaseDate}}


Network & Storage Configuration

6. Query Management and vMotion Networks

Configuration drift in networking often leads to vMotion failures. Use these to verify IP addresses and Subnet masks across all hosts.

Management Network:

Get-VMHost | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Where {$_.ManagementTrafficEnabled} | Select Hostname, PortGroupName, IP, SubnetMask

vMotion Network:

Get-VMHost | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Where {$_.vMotionEnabled} | Select Hostname, PortGroupName, IP, SubnetMask

7. Storage Multipath Policy

To ensure high availability for your storage, you should check that your Multipath Policy is consistent (e.g., Round Robin).  

Elsewhere On TurboGeek:  AWS-Vault Mac: How to Install Vault on MacOS

Get-VMHost | Get-ScsiLun | Select VMHost, ConsoleDeviceName, Vendor, MultipathPolicy


High Availability (HA) & DRS Status

Cluster settings can sometimes be toggled off during maintenance and forgotten. These commands provide a quick health check.  

DRS Check:

Get-VMHost | Get-Cluster | Select Name, DrsEnabled, DrsMode, DrsAutomationLevel

HA Status:

Get-VMHost | Get-Cluster | Select Name, HAFailoverLevel, HARestartPriority, HAIsolationResponse

Storage Reclamation: Snapshots & ISOs

1. Identify Aged Snapshots

Snapshots are temporary. In 2026, keeping a snapshot for more than 72 hours is considered high-risk due to the impact on disk I/O and potential consolidation failures. This script finds every snapshot in your environment older than 7 days and displays its size.

Get-VM | Get-Snapshot | Where-Object {$_.Created -lt (Get-Date).AddDays(-7)} | Select VM, Name, Created, @{N="SizeGB";E={[math]::Round($_.SizeMB/1024,2)}} | Sort-Object Created

2. Unmount Forgotten ISO Files

Leaving an ISO mounted prevents a VM from being migrated via vMotion in some configurations and can cause issues during host maintenance. This one-liner finds every VM with a connected CD drive and unmounts the media.

Get-VM | Get-CDDrive | Where-Object {$_.IsoPath -ne $null} | Set-CDDrive -NoMedia -Confirm:$false


Guest Hygiene: VMTools & Time Sync

3. Mass Audit of VMTools Compliance

Outdated VMTools lead to driver instability and performance loss. Instead of checking each VM tab, this script provides a clear list of any VM where the tools are not “OK.”

Get-VM | Where-Object {$_.ExtensionData.Guest.ToolsStatus -ne "toolsOk"} | Select Name, @{N="Status";E={$_.ExtensionData.Guest.ToolsStatus}}, @{N="Version";E={$_.ExtensionData.Guest.ToolsVersion}}

4. Enforce Host Time Synchronization

For many workloads, keeping the guest clock in sync with the ESXi host is vital for log consistency. This command checks which VMs have this feature enabled.

Get-VM | Select Name, @{N="TimeSync";E={(Get-View $_.Id).Config.Tools.SyncTimeWithHost}}


The “Ghost” Hunter: Orphaned Files & Zombie VMs

5. Find “Orphaned” VMDKs

Orphaned VMDKs are virtual disks that exist on your datastore but are not attached to any VM. They are “dead” space. While a full audit requires a complex script, this one-liner helps you find large files on a datastore that may be candidates for deletion.

Get-Datastore -Name "YourDatastore" | Get-ChildItem -Recurse | Where-Object {$_.Name -like "*.vmdk" -and $_.Length -gt 10GB} | Select Name, DatastoreFullPath, @{N="SizeGB";E={[math]::Round($_.Length/1GB,2)}}

6. Locate Disconnected Hosts

A host in a “Not Responding” or “Disconnected” state can trigger HA events or leave VMs stranded. Use this for a quick cluster-wide health check.

Get-VMHost | Where-Object {$_.ConnectionState -ne "Connected"} | Select Name, ConnectionState, Parent


Security & Network Configuration Audits

7. List All VMs with Raw Device Mappings (RDMs)

RDMs are often used for legacy clusters but complicate backups and migrations. This script identifies every RDM in use so you can plan for their conversion to VMDKs.

Get-VM | Get-HardDisk -DiskType "RawPhysical","RawVirtual" | Select Parent, Name, ScsiCanonicalName, DeviceName

8. Audit VM Network Assignments

During a network migration or VLAN audit, you need to know which port groups are in use. This command maps every VM to its specific network label.

Get-VM | Get-VirtualPortGroup | Select @{N="VM";E={$_.Parent}}, Name, VLanId


Performance & Mass Reporting

9. High-Speed Inventory with Get-View

Standard cmdlets like Get-VM are easy to use but slow. In environments with 5,000+ VMs, use Get-View. It pulls data directly from the API objects, significantly reducing execution time.

Get-View -ViewType VirtualMachine -Property Name, Guest.IPAddress, Summary.Config.NumCpu | Select Name, @{N="IP";E={$_.Guest.IPAddress[0]}}, @{N="CPUs";E={$_.Summary.Config.NumCpu}}

10. Find High-Sample System Warnings

Instead of reading thousands of log lines, this script pulls only the “Warning” level events from the last hour across your vCenter.

Get-VIEvent -MaxSamples 1000 | Where-Object {$_.FullFormattedMessage -like "*warning*" -and $_.CreatedTime -gt (Get-Date).AddHours(-1)} | Select CreatedTime, FullFormattedMessage


Common Troubleshooting

  • Problem: Scripts return no data or “Access Denied.”
    • Fix: Ensure your execution policy allows scripts (Set-ExecutionPolicy RemoteSigned) and that your vCenter user has at least “Read-Only” permissions.
  • Problem: Commands are slow in large environments.
    • Fix: Use the -MaxSamples parameter with Get-VIEvent or target specific clusters instead of the whole vCenter.
  • Problem: “Connect-VIServer” fails.
    • Fix: Check your DNS or use the IP address. Verify that port 443 is open between your workstation and vCenter.

FAQs

Can I run these scripts on Linux?

Yes. PowerCLI is compatible with PowerShell Core, which runs on Linux and macOS. You just need to install the VMware.PowerCLI module through the pwsh terminal.

Are these scripts safe for production?

The commands listed here are “Get” commands, meaning they only read data. They do not change settings or power off VMs, making them safe for production audits.

How do I save the output to a file?

Add | Export-Csv -Path "C:\Report.csv" -NoTypeInformation to the end of any one-liner to save the data for Excel.

Thanks for taking the time to read this article. if you have any questions or feedback, please write in the comment section below.

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

Leave a Reply

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

Translate »