0

I've got the current script that is supposed to log onto vsphere, get all snapshots that are over a week old, and email the results.

Connect-ViServer server

$weekOldSnapshots = (Get-Date).AddDays(-7)
$smtpSrv = "name"
$from = "email"
$to = "email"
$subject = "Snapshot Report"
$body = Get-Snapshot -VM $_ | foreach-object { if($_.Created -gt $weekOldSnapshots){ Select Name, VM, SizeMB}}
$message = new-object Net.Mail.MailMessage($from, $to, $subject, $body)
$smtp = new-object Net.Mail.SMTPclient($smtpSrv)
$smtp.send($message)

When I run this however I'm getting the following error:

enter image description here

Valrok
  • 330
  • 3
  • 11

2 Answers2

0

Figured it out. For any who may be interested in using a code snippet such as this in the future:

Connect-ViServer server
$body = Get-Folder -name vm | Get-VM | Get-Snapshot | Select Name, VM, SizeMb, Created | Out-String 
send-mailmessage -From "myemail.com" -To "myemail.com" -SmtpServer "myserver.com" -Body 
Valrok
  • 330
  • 3
  • 11
0

Alan Renouf's vCheck report will do that and much more for you. https://github.com/alanrenouf/vCheck-vSphere