SCVMM Snapshot Reminder with Powershell


I have created a small Powershell Script which will you remind of existing VM Snapshots. You can use this and create a scheduled task for example each morning and it will send you an email with all existing VM snapshots or checkpoints. The Script uses the Powershell Commands of System Center Virtual Machine Manager 2008 R2 but should also work with System Center Virtual Machine Manager 2012.

# Check for Virtual Machine Manager Snapin
$PSSnapin = Get-PSSnapin | Where-Object { $_.Name -eq "Microsoft.SystemCenter.VirtualMachineManager" }
if($PSSnapin -eq $null)
	Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager
# Connect to SCVMM Server
Get-VMMServer localhost
# Get Snapshots
$snapshots = Get-VMCheckpoint
# Check for existing Snapshots
if ($snapshots.count -gt 0){
	# Create the List of Snapshots
	$info = $snapshots | Format-Table VM, AddedTime, Name -auto | Out-String 
	# Mail Configuration
	# ==================
 	# Configuration
	$emailFrom = "[email protected]"
 	$emailTo = "[email protected]"
 	$emailSubject = "VM Snapshot Reminder"
 	$emailMessage = "You have still some snapshots: `n `n" + $info + "`n Greetings your SCVMM Server"
 	$smtpServer = ""
 	$smtpUserName = "username" # This could be also in e-mail address format
 	$smtpPassword = "password"
	$smtpDomain = ""
	# SMTP Object
	$smtp = New-Object System.Net.Mail.SmtpClient($smtpServer)
	$mailCredentials = New-Object System.Net.NetworkCredential  
 	$mailCredentials.Domain = $smtpDomain
 	$mailCredentials.UserName = $smtpUserName
 	$mailCredentials.Password = $smtpPassword
 	$smtp.Credentials = $mailCredentials  
 	# Send E-Mail
 	$smtp.Send($emailFrom, $emailTo, $emailSubject, $emailMessage)