Hi, Lately i have backups issues everywhere...Here is the newest one.
i User exactly the same script and more than one other farm.
This one SharePoint 2013 farm i get the following error in the failed mail:
Cannot convert value to type System.String
The Script
$ver = $host | select version if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"} Add-PsSnapin Microsoft.SharePoint.Powershell –ErrorAction SilentlyContinue #Add-PsSnapin Microsoft.SharePoint.Powershell $TXTFile = "\\ServerName\sharepoint\SP2013_SiteCollection_Backups\mySites\SPContentDatabase_$today.txt" $List = "\\ServerName\sharepoint\SP2013_SiteCollection_Backups\mySites\List_$today.csv" try { $today = (Get-Date -Format dd-MM-yyyy) $webApplication = Get-SPWebApplication -Identity "http://Webapp.domain" foreach ($site in $webApplication.Sites) { $backupPath = "\\Server\sharepoint\SP2013_SiteCollection_Backups\mySites\" +$Today+"_"+$site.OpenWeb()+".bak" Write-Host "Backing up $site to $backupPath" Write-Host Add-Content -Path $List -Value "$($site.OpenWeb()).bak,$($site.Url)" # backup the site Backup-SPSite -Identity $site.Url -Path $backupPath } # SEND MAIL. $emailFrom = "SPSuccessfull_Backups.domain.za" $emailTo = "a email" # Subject for the notification email. The + “$today” part will add the date in the subject. $subject = "The SharePoint SiteCollection Backup was Successful for "+"$today" # Body or the notification email. The + “$today” part will add the date in the subject. $body = "The SharePoint Web Application was Successful for "+"$today"+". Please find attached is the database report." $webapps = Get-SPWebApplication foreach($webapp in $webapps) { $ContentDatabases = $webapp.ContentDatabases Add-Content -Path $TXTFile -Value "Content databases for $($webapp.url)" foreach($ContentDatabase in $ContentDatabases) { $ContentDatabaseSize = [Math]::Round(($ContentDatabase.disksizerequired/1GB),2) Add-Content -Path $TXTFile -Value "- $($ContentDatabase.Name): $($ContentDatabaseSize)GB" } } # IP address of your SMTP server. Make sure relay Is enabled for the SharePoint server on your SMTP server $smtpServer = "a IP" #$smtp = new-object Net.Mail.SmtpClient($smtpServer) Send-MailMessage -SmtpServer $smtpServer -From $emailFrom -To $emailTo -Subject $subject -Body $body -Attachment $TXTFile, $List #$smtp.Send($emailFrom, $emailTo, $subject, $body) } Catch { $ErrorMessage = $_.Exception.Message # Configure the below parameters as per the above. $emailFrom = "SPFailed_@domain" $emailTo = "a EMail" $subject = "The SharePoint Web Application Backup Job failed on "+"$today" $body = "The SharePoint Web Application Backup Job failed on "+"$today and the reason for failure was: $ErrorMessage." $smtpServer = "a IP" Send-MailMessage -SmtpServer $smtpServer -From $emailFrom -To $emailTo -Subject $subject -Body $body }