Skip to content

Get-HyperVVMCheckpointReport

Hyper-V: Generates a consolidated virtual machine checkpoint report

#Requires -Version 5.1
#Requires -Modules Hyper-V

[CmdletBinding()]
Param (
    [string]$ComputerName = "localhost",

    [PSCredential]$Credential,

    [ValidateSet('All','Standard', 'Recovery', 'Planned', 'Missing', 'Replica', 'AppConsistentReplica','SyncedReplica')]
    [string]$CheckpointType = "All"
)

Process {
    try {
        $params = @{
            'ComputerName' = $ComputerName
            'VMName'       = '*'
            'ErrorAction'  = 'Stop'
        }
        if ($Credential) { $params.Add('Credential', $Credential) }
        if ($CheckpointType -ne "All") { $params.Add('SnapshotType', $CheckpointType) }

        $checkpoints = Get-VMSnapshot @params

        $results = foreach ($cp in $checkpoints) {
            [PSCustomObject]@{
                VMName               = $cp.VMName
                CheckpointName       = $cp.Name
                CheckpointType       = $cp.SnapshotType
                CreationTime         = $cp.CreationTime
                ParentCheckpointName = $cp.ParentCheckpointName
                ComputerName         = $cp.ComputerName
                Timestamp            = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
            }
        }

        Write-Output ($results | Sort-Object VMName, CreationTime)
    }
    catch {
        throw
    }
}

Specifies the name of the Hyper-V host. Defaults to the local machine.

Specifies the credentials to use for the remote connection.

Optional. Filters checkpoints by type (Standard, Recovery, Planned, etc.).

An interactive directory of PowerShell scripts.