← script library

Restart a VMware VM with PowerCLI

VMware & vSphereAugust 17, 2026

Restarts one named VM through PowerCLI, with the VM name as the single value at the top of the script. Small on purpose: it is the building block you drop into a runbook between a change and the check that verifies the change survived a reboot.

powershell
# Set target VM name
$vmName = "VM01"

$server = "esxi.example.local"

Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $true -Confirm:$false

$username = "SE-CredentialsStore.Username.(esxi.example.local)"
$password = "SE-CredentialsStore.Password.(esxi.example.local)"
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($username, $securePassword)

Connect-VIServer -Server $server -Credential $credential

$vm = Get-VM -Name $vmName -ErrorAction SilentlyContinue

if (-not $vm) {
    Write-Host "<WRITE-LOG = ""*ERROR: VM not found: $vmName*"">"
} else {
    try {
        Restart-VM -VM $vm -Confirm:$false | Out-Null
        Write-Host "<WRITE-LOG = ""*SUCCESS: VM $vmName restarted.*"">"
    } catch {
        Write-Host "<WRITE-LOG = ""*ERROR: Failed to restart VM $vmName - $($_.Exception.Message)*"">"
    }
}

Disconnect-VIServer -Server $server -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.