How to monitor and send Hyper-V Checkpoint alert in powershell

How to monitor and send Hyper-V Checkpoint alert in powershell

May 15, 2019

Introduction

Hyper-V is one of virtualization software which has an ability to create a VM checkpoint. We can use this feature to roll back the virtual machine to a previous state. It usually used to take a backup temporarily when we’re doing VM configuration changes, or windows updates.

Instead of using a full backup, it will be more simply to restore it through a VM checkpoint. The application and Operating system running on a virtual machine will be rolled back to the previous state after we do a checkpoint restore.

Hyper-V snapshot
Hyper-V checkpoint illustration
See the checkpoint via powershell
Hyper-V checkpoint illustration in powershell

However, before doing a snapshot, we need to understand that in operating system or application level, it might not fully be supported even though Hyper-V itself support restoring a VM from a snapshot. If we force to restore the application which is not fully supported a snapshot restore, there will be an affect in OS/Application level. For example, if we perform a snapshot restore for a domain controller server, we may face a USN rollback issue. Snapshot is also not working properly to restore the VM which hosted a database application like SQL, Exchange, etc.

So, we need to check the compatibility of the running operating system and application before taking VM checkpoint restore.

If we’re working on a managed customer business environment and handle a lot of customers, we need to make sure that all owned customer’s server is up-to-date. In order to minimize the downtime and speed up the troubleshooting process when the problem comes after applying update, restoring the VM from checkpoint is the best option to do it. We usually keep the snapshot until 5 or 6 days and delete it after it confirmed that all is good.

The problem here is when we’re managing windows update for a lot of customers, in some cases, we don’t remember to clean up the snapshot, and let the VM still in under snapshot that will affect to the storage disk usage and VM performance.

So here is the simple script to send an alert if a VM’s snapshot is available. The script will send an alert contains which the VM has a snapshot, and where the VM is hosted.

You can modify and change the parameter as needed. You can also run this script on a schedule. Please review step by step running a powershell script via task scheduler here.

# ***********************************#
## Hyper V snapshot Alert ##
# ***********************************#

# Customer and server information | filtering for a standard snapshot type only.
$Customer = "Customer Name"
$servers = "SERVER1","SERVER2"
$snapshots = Get-VM -ComputerName $servers | Get-VMSnapshot -SnapshotType "Standard"
 
# Email Configuration
$from = "[email protected]" 
$to = "[email protected]" 
$subject "$customer - Hyper-V Snapshot Alert" 
$smtpServer "mail.amanulloh.com" 

# Check VM Snapshot

if ($snapshots.count -gt 0){
$alert = $snapshots | ft ComputerName, VMName, CreationTime, CheckpointType -auto | Out-String

# Send Alert to customer
Send-MailMessage $from $to $subjet $SmtpServer
-Body "The following is VM list with checkpoint:`n `n $alert`n Note,`n
The checkpoint's type is STANDARD, which means it was created by someone a few days ago (not created by a backup software -like DPM, VEEAM or ACRONIS). `n Don't forget to always delete the snapshot 3 days after Windows Update Maintenance, or inform this to customer to get the customer approval or propose a schedule if needed."
}

Please comment if you think that this article is useful.

Thank you.

Leave a Comments

Your email address will not be published. Required fields are marked *

Copyright ©2023 All rights reserved