← script library

Automating VM Deployment in vSphere Using PowerShell

VMware & vSphereJanuary 6, 2025

In today's IT landscape, automating tasks can save valuable time and reduce human error. PowerShell provides powerful tools to manage VMware vSphere environments, making it easier for system administrators to automate the deployment of virtual machines. The following script connects to a vCenter server, creates a new VM, and powers it on. This example assumes you have the VMware PowerCLI installed and configured on your system.

powershell
# Define variables
$vCenterServer = "vCenter_Server"
$User = "your_username"
$Password = "your_password"
# Connect to vCenter
Connect-VIServer -Server $vCenterServer -User $User -Password $Password

# Define VM parameters
$vmName = "NewVM"
$datastore = "YourDatastore"
$resourcePool = "YourResourcePool"
$vmTemplate = "YourVMTemplate"

# Create new VM from template
$vm = New-VM -Name $vmName -Template $vmTemplate -Datastore $datastore -ResourcePool $resourcePool

# Power on the new VM
Start-VM -VM $vm

# Disconnect from the vCenter
Disconnect-VIServer -Server $vCenterServer -Confirm:$false

Run it across your fleet

This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.

Ready when you are.

Try ServerEngine free for 7 days.