Free SharePoint Backups Email Log

SharePoint, Microsoft, Windows PowerShell

In a very recent post, I showed you a script written in Visual BASIC (vbs) to have your log file emailed to you on a schedule.

This script didn’t work for me on my Windows Server 2008 machines. I got the error “Reportlog.vbs:(52,2). CDO.Message.1: The transport failed to connect to the server.”

I later confirmed this was due to me specifying the wrong server name. But, I went on a small tangent and decided to try PowerShell. The PowerShell version of this script seems to run faster and is easier to understand.

Step 1
Install PowerShell. You can do this on Windows Server 2008 by using the following command: ServerManagerCmd -install PowerShell

Step 2
You’ll need to enable execution of .ps1 files (powershell scripts) first by typing the following into the PowerShell prompt: Set-ExecutionPolicy RemoteSigned

Step 3
Save this script and run it. You can type Drive:\Path\scriptname.ps1 in PowerShell but I like to save this in a batch file and run it using: powershell.exe -noexit &’D:\BackupBatch\reportlog.ps1′

# ##############################################################
# Send Email with Attachment Script
# Usage: $smtp to see settings, or $smtp | gm to see options
# Written by Wahid Saleemi (https://wahidsaleemi.com)
# Enable execution by: Set-ExecutionPolicy RemoteSigned
# ##############################################################
$file = "D:\Backups\Farm\backupdaily.log"
$smtpServer = "mailserver1"

$msg = new-object Net.Mail.MailMessage
$att = new-object Net.Mail.Attachment($file)
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$msg.From = "[email protected]"
$msg.To.Add("[email protected]")
$msg.Subject = "Your SharePoint Backup Report"
$msg.Body = "See attachment"

$msg.Attachments.Add($att)
$smtp.Send($msg)
 
$att.Dispose()


# ##############################################################
# Here's some extra things we could use
# ##############################################################
# $Credentials = new-object System.Net.networkCredential
# $Credentials.domain = "NETBIOS"
# $Credentials.UserName = "xxxx"
# $Credentials.Password = "xxxx"
# $smtp.Credentials = $Credentials
#
# $msg.Sender = "[email protected]"
# $msg.IsBodyHtml = $true

Hope you find this useful. Check out Michael Blumenthal’s blog for more useful PowerShell scripts for SharePoint.

2 comments… add one
  • 562networks Sep 27, 2009 Link Reply

    That sounds great the convention. Let me know how it goes for you.

  • 562networks Sep 26, 2009 Link Reply

    That sounds great the convention. Let me know how it goes for you.

Leave a Reply