| name | govc-vsphere |
| description | Use govc to manage VMware vSphere virtual machines. Use this skill when the user wants to create, clone, snapshot, power on/off, or manage VMs on vSphere/vCenter/ESXi. |
govc - vSphere VM Management
govc is a CLI built on the govmomi Go library for automating VMware vSphere operations.
Installation
Installation methods, PATH setup, and verification: ref-install.md
Connection Setup
Set environment variables for vCenter/ESXi connectivity:
export GOVC_URL=vcenter.example.com
export GOVC_USERNAME=admin@vsphere.local
export GOVC_PASSWORD='secret'
export GOVC_INSECURE=true
Optional defaults to avoid repeating -dc, -ds, -pool, -net on every command:
export GOVC_DATACENTER=mydc
export GOVC_DATASTORE=datastore1
export GOVC_NETWORK='VM Network'
export GOVC_RESOURCE_POOL=/mydc/host/mycluster/Resources
Verify connectivity:
govc about
govc datacenter.info
Getting Help
Always check built-in help for flags and usage:
govc -h
govc <command> -h
Inventory Browsing
govc ls
govc ls /mydc/vm
govc ls -l /mydc/network
govc ls -l /mydc/datastore
govc find / -type m
govc find / -type m -name 'prod-*'
govc find / -type h
govc datacenter.info
govc host.info /mydc/host/mycluster/*
govc datastore.info datastore1
VM Lifecycle
Create a VM
govc vm.create -m 2048 -c 2 -g ubuntu64Guest \
-net.adapter vmxnet3 -disk.controller pvscsi \
-disk 20GB -ds datastore1 my-vm
Clone a VM or template
govc vm.clone -vm template-vm -ds datastore1 new-vm
govc vm.clone -vm template-vm -link new-vm
govc vm.clone -vm template-vm -snapshot base-snap new-vm
Power operations
govc vm.power -on=true my-vm
govc vm.power -s=true my-vm
govc vm.power -off=true my-vm
govc vm.power -r=true my-vm
govc vm.power -suspend=true my-vm
VM info and IP
govc vm.info my-vm
govc vm.info -r my-vm
govc vm.info -json my-vm
govc vm.ip my-vm
govc vm.ip -v4 -a my-vm
Modify a VM
govc vm.change -vm my-vm -m 4096
govc vm.change -vm my-vm -c 4
govc vm.change -vm my-vm -e guestinfo.data=value
Destroy a VM
govc vm.destroy my-vm
Full flag tables and additional examples: ref-commands.md
Snapshots
govc snapshot.create -vm my-vm before-update
govc snapshot.tree -vm my-vm
govc snapshot.tree -vm my-vm -D -i
govc snapshot.revert -vm my-vm before-update
govc snapshot.remove -vm my-vm before-update
govc snapshot.remove -vm my-vm '*'
Disk Management
govc vm.disk.create -vm my-vm -name my-vm/data -size 50G
govc vm.disk.attach -vm my-vm -disk my-vm/shared.vmdk -link=false
govc vm.disk.change -vm my-vm -disk.label "Hard disk 2" -size 100G
Datastore Operations
govc datastore.info datastore1
govc datastore.ls
govc datastore.ls -l path/to/folder
govc datastore.upload local-file.iso remote-path.iso
govc datastore.download remote-path.iso local-file.iso
OVA / OVF Import and Export
govc import.ova -folder=templates my-appliance.ova
govc import.ova -options - my-appliance.ova <<EOF
{"DiskProvisioning": "thin", "MarkAsTemplate": true}
EOF
govc export.ovf -vm my-vm -f=true .
Templates
govc vm.markastemplate /mydc/vm/my-vm
govc vm.markasvm -host=esxi01 /mydc/vm/my-template
govc vm.clone -vm my-template -on=true new-vm
Guest Operations (VMware Tools required)
govc guest.run -vm my-vm /bin/uname -a
govc guest.upload -vm my-vm local.conf /etc/app.conf
govc guest.download -vm my-vm /var/log/app.log ./app.log
govc guest.ls -vm my-vm /tmp/
govc guest.mkdir -vm my-vm /opt/myapp
JSON Output and Scripting
Most commands support -json for machine-readable output:
govc vm.info -json my-vm | jq '.virtualMachines[].guest.ipAddress'
govc find / -type m -json | jq '.[].name'
govc host.info -json /mydc/host/cluster/* | jq '.hostSystems[].summary.config.product.version'
Self-Learning Rule
When you encounter an unfamiliar govc subcommand or need to verify flags, always run:
govc <command> -h
This ensures you use the correct and current syntax.