vCenter Snapshot prüfen und Report als Mail senden

Viele große Unternehmen und Firmen nutzen das vCenter von VMware. Von den Virtuellen Maschinen werden Snapshot erstellt. Wer aber viele VMs hat, also eine große Umgebung der verliert schnell den Überblick. Was kann man also tun? vCenter Snapshot prüfen! Diese kann man sich per Aufgabenplanung 1x im Monat per Mail zusenden lassen 🙂

Snapin das dringend benötigt wird:
“C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\Modules”

vCenter snapshot prüfen

TheDigitalArtist / Pixabay

 

vCenter snapshot prüfen:

Mit folgendem PowerShell Script überprüft ihr auf Snapshots im vCenter. Diese Übersicht wird dann per Mail an euch verschickt.

# PowerShell script to check for VM snapshots and send Email report
$esxhost = 'esxserver.your.domain'
add-pssnapin VMware.VimAutomation.Core
Connect-VIServer -Server $esxhost
# HTML formatting
$a = "<style>"
$a = $a + "BODY{background-color:white;}"
$a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$a = $a + "TH{border-width: 1px;padding: 5px;border-style: solid;border-color: black;foreground-color: black;background-color: LightBlue}"
$a = $a + "TD{border-width: 1px;padding: 5px;border-style: solid;border-color: black;foreground-color: black;background-color: white}"
$a = $a + "</style>"
# Main section of check
Write-Host "Checking VMs for for snapshots"
# Get list of VMs with snapshots
# Note:  It may take some time for the  Get-VM cmdlet to enumerate VMs in larger environments
$ss = Get-vm | Get-Snapshot
if(!$ss) {exit}
#$ss | Select-Object vm, name, description, powerstate | ConvertTo-HTML -head $a -body "<H2>VM Snapshot Report $esxhost</H2>"| Out-File $filename
$body = $ss | Select-Object vm, name, description | ConvertTo-HTML -head $a -body "<H2>VM Snapshot Report $esxhost</H2>"
# Create mail message
$server = "10.10.10.10"
$port = 25
$to      = "[email protected]"
$from    = "[email protected]"
$subject = "VM Snapshot Report $esxhost"
$message = New-Object system.net.mail.MailMessage $from, $to, $subject, $body
# Create SMTP client
$client = New-Object system.Net.Mail.SmtpClient $server, $port
# Credentials are necessary if the server requires the client # to authenticate before it will send e-mail on the client's behalf.
$client.Credentials = [system.Net.CredentialCache]::DefaultNetworkCredentials
# Try to send the message
try {
   
# Convert body to HTML
    $message.IsBodyHTML = $true
# Uncomment these lines if you want to attach the html file to the email message
#   $attachment = new-object Net.Mail.Attachment($filename)
#   $message.attachments.add($attachment)
   
# Send message
    $client.Send($message)
    "Message sent successfully"
}
#Catch error
catch {
    "Exception caught in CreateTestMessage1(): "
}

 

Nach dem Ausführen des Scripts wird euch eine Mail mit dem Report der VM Snapshot gesendet.

🙂

Johannes Huber
 

In seiner Freizeit macht Johannes nichts lieber, als für ITnator Beiträge zu schreiben. Input bekommt er hierfür von Problemen in der IT Administration von Servern, Clients und vielen weiteren IT Komponenten.

Click Here to Leave a Comment Below 0 comments
sidebar