In this blog post i will try to list out some useful PowerCLI scripts.
Allow VMware PowerCLI to run (first time you run PowerCLI on your laptop after install):
Set-ExecutionPolicy RemoteSigned
Power on all VMs on a host that are powered off:
Get-VM | Where-Object {$_.PowerState -eq "PoweredOff"} | foreach { Start-VM -VM $_ }
Create a VM:
New-VM -Name "VM_name" -Datastore "datastore_name" -NumCPU 1 -MemoryGB 1 -CD -DiskGB 10 -NetworkName "VM Network" -DiskStorageFormat Thin
Start all powered off VMs:
get-vm | where PowerState -eq "PoweredOff" | Start-VM
Stop all powered on VMs:
get-vm | where PowerState -eq "PoweredOn" | Stop-VM
Get all DataStores with freespace greater than 20GB:
get-datastore | Where-Object -Property FreeSpaceGB -gt '20'
Get all DataStores with freespace less than 20GB:
get-datastore | Where-Object -Property FreeSpaceGB -lt '20'
Enjoy 😀
Leave a comment