我获得了当前的脚本,该脚本应该登录到 vsphere,获取所有超过一周的快照,然后通过电子邮件发送结果。
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)
但是,当我运行此程序时,出现以下错误:
答案1
搞清楚了。对于将来可能有兴趣使用此类代码片段的任何人:
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
答案2
Alan Renouf 的 vCheck 报告将为您实现这些目标,甚至更多。 https://github.com/alanrenouf/vCheck-vSphere