Skip to content

Instantly share code, notes, and snippets.

@gcanales75
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save gcanales75/923042cd5ab6d8e0f26d to your computer and use it in GitHub Desktop.

Select an option

Save gcanales75/923042cd5ab6d8e0f26d to your computer and use it in GitHub Desktop.
Reporte Snapshot antiguos
#######################
## Reporte Snapshots ##
#######################
## Busca Snapshots con mas de 24 horas, si no encuentra termina script, en caso de
## encontrar Snapshot genera una tabla que pega en un TXT y envia anexado via correo
## electronico.
## Agrega SnapIn de VMware
Add-PSSnapin VMware.VimAutomation.Core
## Conecta con vCenter Server
Connect-VIServer $vCenterServer -User $user -Password $password
## ¡¡Debe estar creada la ruta donde se va a depositar los TXT!! ##
## Elimina archivos previos
Remove-Item "c:\Scripts\Output\reporte-snap.txt"
## Comienza Script :) ##
$ahora = Get-Date
## Importante definir si se van a escanear TODAS las VMs o una muestra (Datacenter,
## Cluster, RPool, etc..)
$VMs = Get-VM
$a = $VMs | Get-Snapshot | where {($ahora - $_.Created).totalhours -ge 24}
if ($a -eq $null) {
write-host "No data"
Disconnect-VIServer -Server * -Force -Confirm:$false
break
}
else
{
$b = foreach ($VM in $VMs) {
Get-Snapshot -VM $VM | where {($ahora - $_.Created).totalhours -ge 24} | FT VM,
@{Name="Tamaño GB";Expression={"{0:N1}" -f $_.SizeGB};a="center"},
@{Name="Fecha";Expression={"{0:dd-MMM-yyyy}" -f $_.Created};a="center"},
@{Name="Dias";Expression={"{0:N0}" -f ((get-date) - $_.Created).days};a="center"},
@{Name="Descripcion";Expression={$_.Description};a="left"} -a
}
$b | Out-File c:\Scripts\Output\reporte-snap.txt -Width 180
}
$file = "c:\Scripts\Output\reporte-snap.txt"
$SMTPServer = "miSMTPServer"
$puerto = "puerto"
$password = "miPassword"
$buzondest = "[email protected]"
$buzonorig = "[email protected]"
$mailsubject = "TextoSubjectMail"
#Send mail (con autenticacion SSL)
$secpasswd = ConvertTo-SecureString $password -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($buzonorig, $secpasswd)
Send-MailMessage -SmtpServer $SMTPServer -To $buzondest -From $buzonorig -bodyashtml $file -Port $puerto -UseSsl:$true -Credential $cred -Subject $mailsubject -attachment $file
Disconnect-VIServer -Server * -Force -Confirm:$false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment