Introduction

Get-ChildItem "D:VMBackups" -Filter *.ova | Where-Object {$_.LastWriteTime -lt (Get-Date).AddDays(-10)} | Remove-Item


Diagram: DR Workflow with PowerCLI


Use Case: Patch Tuesday Recovery Plan

$criticalVMs = "SQLApp01", "Web01", "DC01"
$criticalVMs | ForEach-Object {
Get-VM -Name $_ | New-Snapshot -Name "PreEvent" -Description "Scheduled DR snapshot"
}


Step 2: Export VMs to OVF or OVA Format

Remove snapshots older than 10 days:

Disaster recovery is all about preparation and repeatability. Whether you are planning for hardware failure, site outage, or ransomware rollback, PowerCLI allows you to automate every step of your DR workflow. This article focuses on DR tasks that can be executed on-demand or scheduled, ensuring readiness and reducing recovery time.

Next article will focus on:

Get-VM | Get-Snapshot | Where-Object {$_.Created -lt (Get-Date).AddDays(-10)} | Remove-Snapshot -Confirm:$false

Export-VApp -VM "SQLApp01" -Destination "D:VMBackups" -Format Ovf

You can bundle these into a single scheduled script.$vmList = "SQLApp01","Web01","DC01"
$report = @()Get-Datastore | Select Name, FreeSpaceGB, CapacityGB


Step 4: Simulate DR Plan with Failover Checklist

$report | Export-Csv "C:ReportsDR_Readiness_Checklist.csv" -NoTypeInformation

Get-VM -Name "SQLApp01" | New-Snapshot -Name "PrePatch_2025_07_20" -Description "Before July Patch Maintenance"

Covered tasks:


Troubleshooting

Issue Fix
Snapshot fails due to disk lock Ensure backup tasks are not in progress
Export-VApp throws access denied Run PowerShell as admin and validate write path
Export fails silently Use -Confirm:$false -Verbose to get diagnostics
Host validation script returns blank Ensure vCenter connection is valid and cluster is populated

What’s Next

Get-VM -Name "Web01","SQLApp01" | ForEach-Object {
Export-VApp -VM $_ -Destination "D:VMBackups" -Format Ova
}


Step 3: Validate DR Host and Resource Availability

Get-VMHost | Select Name, ConnectionState, Version, MaxVcpus, MemoryTotalGB

Validate target datastore free space:

  • Using PowerCLI for compliance audits
  • Mapping configuration against NIST and CIS standards

Similar Posts