1 0

Export all Hyper-V VMs

$ExportPath = "\\san\share"
$VMs = Get-VM
$TotalVMs = $VMs.Count
$Counter = 0
foreach ($VM in $VMs) {
    $Counter++
    $VMName = $VM.Name
    Write-Host "[$Counter/$TotalVMs] Starting export of: $VMName" -ForegroundColor Green
    $StartTime = Get-Date
    Export-VM -Name $VMName -Path $ExportPath
    $EndTime = Get-Date
    $Duration = $EndTime - $StartTime
    Write-Host "[$Counter/$TotalVMs] Completed: $VMName (took $($Duration.TotalMinutes.ToString('F1')) minutes)" -ForegroundColor Yellow
}
Write-Host "All VM exports completed!" -ForegroundColor Cyan