Last active
October 30, 2015 03:46
-
-
Save gcanales75/01eb2b626ea42b5fc43b to your computer and use it in GitHub Desktop.
Reporte de Utilizacion Datastores VMware y envio mail en HTML
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ######################################################### | |
| ## Generacion de reporte de utilizacion de espacio | |
| ## en Datastores VMware y envio por correo electronico | |
| ## como HTML/CSS | |
| ######################################################### | |
| ## CSS | |
| $head = @" | |
| <style> | |
| table { | |
| Background-Color: rgb(252, 252, 252); | |
| border-style: solid; | |
| border-width: 1px; | |
| Font-Family: Tahoma; | |
| Font-Size: 8pt; | |
| margin-bottom: 0px; | |
| margin-left: 4px; | |
| margin-right: 0px; | |
| margin-top: 0px; | |
| } | |
| tr:hover td { | |
| Background-Color: #3ab732; | |
| Color: white; | |
| } | |
| tr:nth-child(even) { | |
| Background-Color: rgb(242, 242, 242); | |
| } | |
| th { | |
| Color: navy; | |
| padding-bottom: 1px; | |
| padding-left: 4px; | |
| padding-right: 4px; | |
| padding-top: 1px; | |
| Text-Align: Left; | |
| } | |
| td { | |
| padding-bottom: 1px; | |
| padding-left: 4px; | |
| padding-right: 4px; | |
| padding-top: 1px; | |
| Vertical-Align: Top; | |
| } | |
| </style> | |
| "@ | |
| ## Inicia Sesion en vCenter Sever | |
| $vCenter = "mi_servidor_vCenter" | |
| $usario = "usuario_admin_vCenter" | |
| $vCenterpass = "password_usuario_vCenter" | |
| Add-PSSnapin VMware.VimAutomation.Core | |
| Connect-VIServer -server $vCenter -user $usuario -password $vCenterpass | |
| ## Datos | |
| $reporte = Get-Datastore | | |
| Select @{Name="Datastore";Expression={$_.name}}, | |
| @{Name="Capacidad GB";Expression={"{0:N1}" -f $_.capacityGB}}, | |
| @{Name="Disponible GB";Expression={"{0:N1}" -f $_.freespaceGB}}, | |
| @{Name="Utilizacion(%)";Expression={ "{0:N1}" -f (((($_.freespaceGB / $_.capacityGB) -1) * 100) * -1) }} | |
| $body = $reporte | ConvertTo-Html -Head $head -PreContent "<H2>Reporte Datastores</H2>" | Out-String | |
| ## Variables envio de correo | |
| $passwd = "mi_contrasenia" | |
| $sender = "correo-envio@ejemplo.com" | |
| $destinatario = "correo-destinatario@ejemplo.com" | |
| $SMTP = "mi_servidor_de_SMTP" | |
| $puerto = "puerto_SMTP" | |
| #Send mail | |
| $secpasswd = ConvertTo-SecureString $passwd -AsPlainText -Force | |
| $cred = New-Object System.Management.Automation.PSCredential ($sender, $secpasswd) | |
| Send-MailMessage -SmtpServer $SMTP -To $destinatario -From $sender -Port $puerto -UseSsl:$true -Credential $cred -Subject "Reporte Utilizacion Storage" -Body $body -BodyAsHtml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment