Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 252940

Re: PowerCLI script to alert on snapshots in vSphere

$
0
0

Hi there,

 

I copied and paste the info into the script when i go to the run the script I get this error.

 

 

Export-Csv : Cannot bind parameter 'Delimiter'. Cannot convert value "Send-MailMessage" to type "System.Char". Error: "String must be exactly one character long."
At C:\Users\ray00055\Desktop\Snapshots-msf1vvcs01p-2.ps1:34 char:90
+ ... date.year).csv"Send-MailMessage -To "$toAddr" -From "$fromAddr" -Subject "WARNIN ...
+                    ~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Export-Csv], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.ExportCsvCommand

Remove-Item : Cannot find path 'C:\Users\ray00055\Desktop\SnapshotReport 2-27-2013.csv' because it does not exist.
At C:\Users\ray00055\Desktop\Snapshots-msf1vvcs01p-2.ps1:35 char:1
+ Remove-Item "SnapshotReport $($date.month)-$($date.day)-$($date.year).csv"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\ray000...t 2-27-2013.csv:String) [Remove-Item], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.RemoveItemCommand

 

Connect-VIServer -server $vcenterserver
$date = Get-Date
$VMsWithSnaps = @(Get-VM | Get-Snapshot | Select VM,Name,Created,sizemb)

 

# Make sure the body isn't empty. If it is, skip this part and exit the script.
if($VMsWithSnaps -ne $null){
    $body = @("       
<center><table border=1 width=50 % cellspacing=0 cellpadding=8 bgcolor=Black cols=3>       
<tr bgcolor=White><td>Virtual Machine</td><td>Snapshot</td><td>Size in MB</td><td>Creation Time</td></tr>")


    $i = 0
    do {
    if($i % 2){$body += "<tr bgcolor=#D2CFCF><td>$($VMsWithSnaps[$i].VM)</td><td>$($VMsWithSnaps[$i].Name)</td><td>$($VMsWithSnaps[$i].Sizemb)</td><td>$($VMsWithSnaps[$i].Created)</td></tr>";$i++}
    else {$body += "<tr bgcolor=#EFEFEF><td>$($VMsWithSnaps[$i].VM)</td><td>$($VMsWithSnaps[$i].Name)</td><td>$($VMsWithSnaps[$i].Sizemb)</td><td>$($VMsWithSnaps[$i].Created)</td></tr>";$i++}
    }
    while ($VMsWithSnaps[$i] -ne $null)

    $body += "</table></center>"

# Send email alerting recipients about snapshots.
if($attachmentPref){
$VMsWithSnaps | Export-CSV "SnapshotReport $($date.month)-$($date.day)-$($date.year).csv"Send-MailMessage -To "$toAddr" -From "$fromAddr" -Subject "WARNING: VMware Snapshots found on msf1vvcs01p" -Body "$body" -Attachments "SnapshotReport $($date.month)-$($date.day)-$($date.year).csv" -SmtpServer "$smtpsrv" -BodyAsHtml       
Remove-Item "SnapshotReport $($date.month)-$($date.day)-$($date.year).csv"
}
Else{
Send-MailMessage -To "$toAddr" -From "$fromAddr" -Subject "WARNING: VMware Snapshots found on msf1vvcs01p" -Body "$body" -SmtpServer "$smtpsrv" -BodyAsHtml  
}
}
Else{
    Send-MailMessage -To "$toAddr" -From "$fromAddr" -Subject "WARNING: NO VMware Snapshots found on msf1vvcs01p" -Body "" -SmtpServer "$smtpsrv"
}

Disconnect-VIServer -Server $vcenterserver -Confirm:$false
exit


Viewing all articles
Browse latest Browse all 252940

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>