Every vSphere admin has a script they are slightly afraid of. Mine used to be the snapshot clean-up job: one Get-VM | Get-Snapshot | Remove-Snapshot with a filter that was correct right up until the day it was not. The fix was not a better filter. It was never running a new or changed script against production first.
This is part 1 of a hands-on automation series for vSphere admins. In this post we build a throwaway vCenter on a laptop with vcsim, the vCenter simulator from the open-source govmomi project, point govc and PowerCLI at it, run a real daily-report script, and record an inventory so you can replay it later. Everything below was run on a MacBook, and the screenshots are the actual output.
What vcsim is, and what it is not
vcsim is a single Go binary that answers the vSphere Web Services (SOAP) API the way vCenter does. It creates an inventory of datacenters, clusters, hosts, datastores, networks and VMs in memory, runs tasks (power on, snapshot, maintenance mode, clone), and accepts the same calls that govc, PowerCLI, pyVmomi and Terraform make. It needs no ESXi, no licence and no hardware.
It is a simulator, not a nested lab. There is no guest OS, no real disk I/O, and performance counters are synthetic. It is the right tool for testing the logic of a script (does my filter pick the right VMs, does my report handle a host in maintenance mode, does my loop survive an empty cluster), not for testing performance or guest operations.
Step 1: build vcsim
vcsim lives in its own Go module inside the govmomi repository, so go install github.com/vmware/govmomi/vcsim@latest fails with a “replace directives” error. Building from a tagged checkout works every time. Match the tag to your govc version (govc version):
git clone --depth 1 --branch v0.55.1 https://github.com/vmware/govmomi.git
cd govmomi/vcsim
go build -o ~/bloglab/bin/vcsim .
Step 2: start a small estate
The flags describe the topology. I like two clusters of three hosts with two datastores and no default VMs, then I create my own VMs with names that look like a real estate, because filters on names are where scripts usually go wrong.
vcsim -l 127.0.0.1:8989 -dc 1 -cluster 2 -host 3 -standalone-host 0 \
-pool 0 -ds 2 -vm 0 -app 0 &
export GOVC_URL=https://user:pass@127.0.0.1:8989/sdk
export GOVC_INSECURE=1
Then populate it. This is the exact script used for the screenshots:
#!/bin/bash
# Populate vcsim with a small estate: 2 clusters, 8 VMs, a few snapshots.
set -e
mk(){ govc vm.create -c $3 -m $4 -g ubuntu64Guest -net "VM Network" -ds $5 \
-pool /DC0/host/$2/Resources -on=$6 $1; }
mk web-01 DC0_C0 2 4096 LocalDS_0 true
mk web-02 DC0_C0 2 4096 LocalDS_0 true
mk app-01 DC0_C0 4 8192 LocalDS_0 true
mk sql-01 DC0_C1 8 32768 LocalDS_1 true
mk sql-02 DC0_C1 8 32768 LocalDS_1 false
mk jump-01 DC0_C1 2 4096 LocalDS_1 true
mk tmpl-ubuntu-2404 DC0_C0 2 4096 LocalDS_0 false
mk old-test-07 DC0_C1 2 2048 LocalDS_1 false
govc snapshot.create -vm app-01 pre-patch-2026-11
govc snapshot.create -vm sql-01 before-cu-upgrade
govc snapshot.create -vm sql-01 before-cu-upgrade-2
govc snapshot.create -vm old-test-07 test

Step 3: connect PowerCLI (and the one gotcha)
My first attempt passed the server as 127.0.0.1:8989 and PowerCLI answered with Invalid URI: The hostname could not be parsed. Connect-VIServer wants the port as its own parameter:
Set-PowerCLIConfiguration -InvalidCertificateAction Ignore -Scope Session -Confirm:$false
Connect-VIServer -Server 127.0.0.1 -Port 8989 -User user -Password pass
Keep -InvalidCertificateAction Ignore at Session scope. vcsim uses a self-signed certificate, and you do not want that setting to follow you to production at User scope.
Step 4: a daily report worth running every morning
This is the report I start every new estate with. It answers four questions: what is powered off, which snapshots are older than they should be, which datastores are running out of space, and which hosts are not connected or are in maintenance mode.
param(
[string]$Server = '127.0.0.1',
[int]$Port = 8989,
[int]$SnapshotAgeDays = 0, # in production use 3; 0 lets the lab show every snapshot
[int]$DatastoreFreePct = 20
)
$cred = New-Object System.Management.Automation.PSCredential('user', (ConvertTo-SecureString 'pass' -AsPlainText -Force))
Connect-VIServer -Server $Server -Port $Port -Credential $cred -Force | Out-Null
"== Powered-off VMs (candidates for review) =="
Get-VM | Where-Object PowerState -eq 'PoweredOff' |
Select-Object Name, NumCpu, MemoryGB, @{n='Cluster';e={(Get-Cluster -VM $_).Name}} | Format-Table -AutoSize
"== Snapshots older than $SnapshotAgeDays day(s) =="
Get-VM | Get-Snapshot | Where-Object { $_.Created -lt (Get-Date).AddDays(-$SnapshotAgeDays) } |
Select-Object VM, Name, Created, @{n='SizeGB';e={[math]::Round($_.SizeGB,2)}} | Format-Table -AutoSize
"== Datastores under $DatastoreFreePct% free =="
$ds = Get-Datastore | Select-Object Name, @{n='CapacityGB';e={[math]::Round($_.CapacityGB)}},
@{n='FreePct';e={[math]::Round(100*$_.FreeSpaceGB/$_.CapacityGB,1)}}
$ds | Format-Table -AutoSize
$low = $ds | Where-Object FreePct -lt $DatastoreFreePct
if (-not $low) { "OK: no datastore under $DatastoreFreePct% free" }
"== Hosts not connected or in maintenance =="
Get-VMHost | Where-Object { $_.ConnectionState -ne 'Connected' } |
Select-Object Name, ConnectionState, @{n='Cluster';e={$_.Parent.Name}} | Format-Table -AutoSize
Disconnect-VIServer -Server $Server -Confirm:$false
Before running it I put one host into maintenance mode with govc host.maintenance.enter /DC0/host/DC0_C1/DC0_C1_H2, so the last section has something to catch. This is the real value of a simulator: you can create the awkward states on purpose.

Step 5: record an inventory and replay it
This is the feature that makes vcsim more than a toy. govc object.save writes the inventory of whatever govc is pointed at to a folder, and vcsim -load starts a simulator from that folder. Point the save at a real vCenter with a read-only account and you get a copy of its structure (clusters, hosts, VMs, snapshots, networks) to test against, without any of its data. Scrub the folder before sharing it, because names and configuration are in there.
govc object.save -d lab-inventory
vcsim -l 127.0.0.1:8989 -load lab-inventory &
govc find / -type m -runtime.powerState poweredOff
govc snapshot.tree -vm sql-01

Where the simulator will mislead you
- Sizes are not real. Snapshot SizeGB is 0 and datastore free space does not track what the VMs would use. Test the logic of capacity reports here, and the thresholds against real data.
- The API version is older than your vCenter. By default vcsim reports API version 6.5 (you can see it in the screenshot). The
-api-versionflag raises the reported version, but the simulator only implements what govmomi implements, so cmdlets and properties that need newer API features may still be missing. - No guest operations. There is no VMware Tools inside a simulated VM, so Invoke-VMScript and guest file copies are out of scope.
- Authentication is relaxed. By default vcsim accepts any username and password. Use the
-usernameand-passwordflags if your script handles credentials and you want to test failure paths.
How I use this day to day
- Every new or changed script runs against vcsim first, with the awkward states created on purpose: a host in maintenance, a VM with a snapshot chain, an empty cluster.
- Anything destructive (remove, delete, move) gets a
-WhatIfrun against the simulator, then a real run against the simulator, then a-WhatIfrun against production. - A saved inventory folder lives next to the script in Git, so a colleague can reproduce exactly what I tested.
FAQ
Does PowerCLI work against vcsim? Yes. Connect with -Server and -Port as separate parameters and ignore the certificate at session scope. The screenshots above were taken with PowerCLI on PowerShell 7 on macOS.
Can I test Terraform or pyVmomi the same way? Yes. vcsim answers the same SOAP API, so any client that talks to vCenter can point at https://127.0.0.1:8989/sdk.
Is it safe to run object.save against production? It is read-only, but it walks the whole inventory. Use a read-only account, run it outside business hours on large vCenters, and treat the output folder as sensitive.
Next in this series
Part 2 turns the daily report into an HTML email and adds the checks I get asked about most: VMs with old VMware Tools, hosts with mismatched builds in the same cluster, and orphaned files on datastores. All of it tested against this same simulator first.
What is the one script in your environment you would most like to test this way before the next change window? Tell me in the comments and I will cover it in the series.

Leave a Reply