Skip to content

Instantly share code, notes, and snippets.

Created February 21, 2014 18:55
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# Simple Backup to Email script
# Requirements: 7-Zip to be installed
# User Variables
# Folder to zip and send
$TheFolder = "E:\ZipMe"
# (sub)Folder to exclude
$fExclude = "SkipMe"
# Path to zip file (output)
$theDay = Get-Date -Format "MMddyyyy"
$theTime = Get-Date -Format "HHmmss"
$outfile = "E:\zippedfolder_$theDay-$theTime.bak"
# Path to 7-zip
$7z = "E:\Program Files\7-Zip\7z.exe"
# 7-zip Arguments
$7zArgs = "a", "$outfile", "$TheFolder", "-xr!$fExclude"
# Email setup
$emailsubject = "Archive - " + $TheFolder + " - Rename file extension to .7z"
$sendTo = ""
$sendFrom = ""
$smtpserver = ""
# End User Variables
# Zip it up and save 7z output as email msg body
[string]$Body = & $7z $7zArgs
# Send output to email
send-mailmessage -to $sendTo -from $sendFrom -Subject $emailsubject -smtpserver $smtpserver -Body $Body -Attachments $outfile
#Remove zip file
Remove-Item $outfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment