@" =============================================================================== Title: Get-VmwareSnaphots.ps1 Description: List snapshots on all VMWARE ESX/ESXi servers as well as VM's managed by Virtual Center. Requirements: Windows Powershell and the VI Toolkit Usage: .\Get-VmwareSnaphots.ps1 Author: Chris Uys =============================================================================== "@ #Global Functions #This function generates a nice HTML output that uses CSS for style formatting. function Generate-Report { Write-Output "" Foreach ($snapshot in $report){ Write-Output " " } Write-Output "
VMware Snaphot Report
VM Name Snapshot Name Date Created Description Host
$($snapshot.vm)$($snapshot.name)$($snapshot.created)$($snapshot.description)$($snapshot.host)
" } #Login details for standalone ESXi servers $username = 'root' $password = 'ESXiPassword' #Change to the root password you set for you ESXi server #List of servers including Virtual Center Server. The account this script will run as will need at least Read-Only access to Cirtual Center $ServerList = "ESXiServer1","ESXiServer2","VCServer" #Chance to DNS Names/IP addresses of your ESXi servers or Virtual Center Server #Initialise Array $Report = @() #Get snapshots from all servers foreach ($server in $serverlist){ # Check is server is a Virtual Center Server and connect with current user if ($server -eq "VCServer"){Connect-VIServer $server} # Use specific login details for the rest of servers in $serverlist else {Connect-VIServer $server -user $username -password $password} get-vm | get-snapshot | %{ $Snap = {} | Select VM,Name,Created,Description,Host $Snap.VM = $_.vm.name $Snap.Name = $_.name $Snap.Created = $_.created $Snap.Description = $_.description $Snap.Host = $_.vm.host.name $Report += $Snap } } # Generate the report and email it as a HTML body of an email Generate-Report > "VmwareSnapshots.html" IF ($Report -ne ""){ $SmtpClient = New-Object system.net.mail.smtpClient $SmtpClient.host = "smtp.hostname.local" #Change to a SMTP server in your environment $MailMessage = New-Object system.net.mail.mailmessage $MailMessage.from = "System.Automation@hostname.com" #Change to email address you want emails to be coming from $MailMessage.To.add("it@hostname.com") #Change to email address you would like to receive emails. $MailMessage.IsBodyHtml = 1 $MailMessage.Subject = "Vmware Snapshots" $MailMessage.Body = Generate-Report $SmtpClient.Send($MailMessage)}