, , , ,

Windows Server 2012: Hyper-V Snapshot Reminder

Windows Server 8

Last year I created a Windows PowerShell script for System Center Virtual Machine Manager which checks all the Virtual Machines for Snapshots and if you have any it will send you an E-Mail and it will remind you about that.
It were just some small changes from the SCVMM PowerShell cmdlets to the Windows Server 2012 PowerShell cmdlets.

Hyper-V Snapshots Reminder


# Get Snapshots
$snapshots = Get-VM | Get-VMSnapshot
 
# Check for existing Snapshots
if ($snapshots.count -gt 0){
 
    # Create the List of Snapshots
    $info = $snapshots | Format-Table VMName, 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 Hyper-V Server"
    $smtpServer = "mail.server.com"
    $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)
 }


2 responses

  1. Ruch Peter Avatar
    Ruch Peter

    Hallo Thomas
    Betreffend dem Befehl Get-VMSnapshot, so wie du schreibst, führst du diesen auf dem SCVMM- und nicht auf einem Hyper-V Server aus.
    Wenn ich den Befehl auf einem Hyper-V Server ausführe, funktioniert er ohne Probleme. Wenn ich den Befehl jedoch auf dem SCVMM-Server ausführe kommt die Fehlermeldung, dass der VMM Service nicht laufe. Was muss auf dem SCVMM noch installiert werden damit der VMM Service zur VErfügung steht?
    Danke und Gruess
    Pesche

    1. Thomas Maurer Avatar

      Auf dem VMM Server sind es die VMM cmdlets Get-VMCheckpoint
      Und auf Hyper-V sind es die Hyper-V cmdlets Get-VMSnapshot

      VMM: https://www.thomasmaurer.ch/2011/09/scvmm-snapshot-reminder-with-powershell/
      Hyper-V: https://www.thomasmaurer.ch/2012/04/windows-server-2012-hyper-v-snapshot-reminder/

      Gruss Tom

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.