You are on page 1of 1

$VirtualMachine = "kaseya test"

$HyperVHost = $env:COMPUTERNAME
$SnapshotDays = 3
#create hyperv snapshot and delete older then

Write-Host (Get-Date)": Creating snapshot of $VirtualMachine"


$DateFormat = Get-Date -Format yyyy.MM.dd
$Snapshot = $virtualmachine.Name + "-" + $DateFormat

CheckPoint-VM -ComputerName $HyperVHost -Name $VirtualMachine -Snapshotname


$Snapshot
Start-Sleep -Seconds 2

#Removing the old snapshots

Remove-VMSnapshot (Get-VMSnapshot -ComputerName $HyperVHost -VMName $VirtualMachine


| Where-Object {$_.CreationTime -lt (Get-Date).AddDays(-$SnapshotDays)})

You might also like