jdandy0016
Contributor
Contributor

Script to Show VM's with Snapshots

I would like to create a PowerCLI script that shows all VM's with snapshots, the size of the snapshot and export it to a pdf or cvs.

I can easily run the report in vRealize but I would like this automated and sent to an email.

Thank you

Tags (1)
0 Kudos
1 Reply
LucD
Leadership
Leadership

You could do something like this

$fileName = '.\report.csv'

Get-VM | Get-Snapshot |

Select-Object -Property @{N = 'VM'; E = { $_.VM.Name } }, Name, Created,

@{N = 'SizeGB'; E = { [math]::Round($_.SizeGB, 1) } } |

Export-Csv -Path $fileName -NoTypeInformation -UseCulture


$sMail = @{

  To = 'user@domain'

  From = 'user@domain'

  Subject = 'Snapshot Report'

  SmtpServer = 'mail.domain'

  Attachments = $fileName

}

Send-MailMessage @sMail


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos