Single Blog

Get-VmwareSnaphots.ps1

——

@”

===============================================================================

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: Last Updated by Sravan Kumar E

===============================================================================

“@

#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 NameSnapshot NameDate CreatedDescriptionHost
$($snapshot.vm)$($snapshot.name)$($snapshot.created)$($snapshot.description)$($snapshot.host)

}

#Login details for standalone ESXi servers

$username = ‘administrator’

$password = ‘password’ #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 = “10.91.42.21” #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 “10.91.42.21”){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 = “10.91.40.35” #Change to a SMTP server in your environment

$MailMessage = New-Object system.net.mail.mailmessage

$MailMessage.from = “[email protected]” #Change to email address you want emails to be coming from

$MailMessage.To.add(“[email protected]”) #Change to email address you would like to receive emails.

$MailMessage.IsBodyHtml = 1

$MailMessage.Subject = “Vmware Snapshots”

$MailMessage.Body = Generate-Report

$SmtpClient.Send($MailMessage)}

——-

Comments (0)

Post a Comment