#System Variable for backup Procedure
$date = Get-Date -Format yyyMMdd
net use w: \\192.168.100.110\Content /user:backupadm backuppwd
New-PSDrive -Name "Backup" -PSProvider Filesystem -Root "\\192.168.100.110\Content"
$source = "D:\BackupS"
$destination = "backup:\$date"
$path = test-Path $destination
#Email Variables
$smtp = "192.168.100.10"
$from = "PowerShell_Backup@shazi.twbbs.org"
$to = "eric@net.tw"
$body = "Log File of Eric bacupk is attached, backup happens on of Date: $date"
$subject = "Eric Backup on $date"
# Backup Process started
if ($path -eq $true) {
write-Host "Directory Already exists"
Remove-PSDrive "Backup"
} elseif ($path -eq $false) {
cd backup:\
mkdir $date
copy-Item -Recurse $source -Destination $destination
$backup_log = Dir -Recurse $destination | out-File "$destination\backup_log.txt"
$attachment = "$destination\backup_log.txt"
#Send an Email to User
send-MailMessage -SmtpServer $smtp -From $from -To $to -Subject $subject -Attachments $attachment -Body $body -BodyAsHtml
write-host "Backup Sucessfull"
cd c:\
Remove-PSDrive "Backup"
}
沒有留言:
張貼留言