Free SharePoint Backups Email Log

Microsoft, SharePoint, 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′

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# ##############################################################
# Send Email with Attachment Script
# Usage: $smtp to see settings, or $smtp | gm to see options
# Written by Wahid Saleemi (http://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 = "sharepoint@domain.com"
$msg.To.Add("wahid.saleemi@domain.com")
$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 = "portal.sharepoint@domain.com"
# $msg.IsBodyHtml = $true

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

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

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

  • 562networks Sep 26, 2009

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

Leave a Comment

%d bloggers like this: