Created
February 21, 2014 18:55
-
-
Save smasterson/9140810 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 = "[email protected]" | |
$sendFrom = "[email protected]" | |
$smtpserver = "your.relay.com" | |
# 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