Hey all,
I got a snapshot setup to be created automatically within the vcenter once a month and need a script to remove the snapshot 4 days later. I am testing this script on just one snap to start but will need to expand it. Also at the end I wanted it to email me just to confirm things were done.
#############################
# Connect to vCenter #
#############################
add-pssnapin VMware.VimAutomation.Core
Connect-VIServer 127.0.0.1 -Protocol https -User <USER> -Password <PW>
#############################
# Content #
#############################
Get-VM -Name <VM> | Get-Snapshot | Remove-Snapshot
##################
# Mail variables #
##################
$enablemail="yes"
$smtpServer = "<SERVER>"
$mailfrom = "<ADDY>"
$mailto = "<ADDY>"
######################
# E-mail HTML output #
######################
if ($enablemail -match "yes")
{
$msg = new-object Net.Mail.MailMessage
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = $mailfrom
$msg.To.Add($mailto)
$msg.Subject = “Monthly Snapshots Removed”
$msg.Body = “Snapshots are removed. Have a good day!”
$smtp.Send($msg)
}
##############################
# Disconnect session from VC #
##############################
disconnect-viserver -confirm:$false