<# .SYNOPSIS Report Checkpoint Hyper-V .DESCRIPTION Script per recuperare l'elenco delle VM Hyper-V locali, contare i relativi checkpoint (snapshot) ed esportare il risultato in un file CSV. #> # Configurazione percorso di esportazione $ExportPath = "C:\temp\Report_Checkpoint_HyperV.csv" # Verifica che la directory di destinazione esista, altrimenti la crea $TargetDir = Split-Path $ExportPath if (-not (Test-Path $TargetDir)) { New-Item -ItemType Directory -Path $TargetDir | Out-Null } Write-Host "Recupero delle informazioni dalle VM in corso..." -ForegroundColor Cyan # Recupera tutte le Virtual Machine $VMs = Get-VM # Elabora i dati creando oggetti personalizzati $Report = foreach ($VM in $VMs) { # L'uso di @() garantisce che la proprietà .Count restituisca un valore corretto # anche se ci sono 0 o esattamente 1 checkpoint. $Checkpoints = @(Get-VMSnapshot -VMName $VM.Name) [PSCustomObject]@{ NomeVM = $VM.Name StatoOperativo = $VM.State NumeroCheckpoint = $Checkpoints.Count } } # Double check: stampa a video i risultati per un controllo rapido Write-Host "`n--- Anteprima Report ---" -ForegroundColor Yellow $Report | Format-Table -AutoSize # Esportazione del file CSV $Report | Export-Csv -Path $ExportPath -NoTypeInformation -Encoding UTF8 -Delimiter "," Write-Host "Report generato e salvato correttamente in: $ExportPath" -ForegroundColor Green