diff --git a/OffloadKACEBackupsFTP.ps1 b/OffloadKACEBackupsFTP.ps1 index 4782e2a..6e08220 100644 --- a/OffloadKACEBackupsFTP.ps1 +++ b/OffloadKACEBackupsFTP.ps1 @@ -4,16 +4,16 @@ $FTPUser = "kbftp" #User for KACE FTP server (Can only be kbftp) $FTPPass = "getbxf" #Password for KACE FTP server (getbxf is default, but can be changed at Settings>Security Settings>New FTP user password $DaystoRetain = 30 #Days of backups to retain on the desitnation location. Backups older than 30 days will be automatically deleted. -$EmailUser = "domain\username" #Username for email account to send error emails from (Recommend using service account) +$EmailUser = "domain\username" #Username for email account to send emails from (Recommend using service account) $EmailFrom = "serviceaccount@domain.com" #Email address for the selected account -$EmailPass = ConvertTo-SecureString "P@Ssw0rD" -AsPlainText -Force #Password for email account for sending error emails -$EmailTo = "serveradmin@domain.com" #Email which will recieve error emails -$PSEmailServer = "smtp.domain.com" #SMTP server for sending error emails +$EmailPass = ConvertTo-SecureString "P@Ssw0rD" -AsPlainText -Force #Password for email account for sending emails +$EmailTo = "serveradmin@domain.com" #Email which will recieve emails +$PSEmailServer = "smtp.domain.com" #SMTP server for sending emails #------------------------------------------------------------------------------------ $cred = new-object -typename System.Management.Automation.PSCredential ` - -argumentlist $EmailUser, $EmailPass + -argumentlist $EmailUser , $EmailPass function Write-Logline ($String){"[ "+(Get-Date).ToString()+" ] "+$String | Out-File $LogfilePath -encoding ASCII -append} @@ -293,9 +293,19 @@ function Send-Error-Email ($ErrorText) { echo $ErrCt $Subjectvar = "Backup Log, Error Count: $ErrCt" $Subject = [string] $Subjectvar - Send-MailMessage -To $EmailTo -from $EmailFrom -Subject $Subject -BodyAsHtml $Body -Port 587 -Priority: High + Send-MailMessage -To $EmailTo -from $EmailFrom -Subject $Subject -BodyAsHtml $Body -Port 25 -Priority: High +} +function Send-Log-Email ($LogText) { + Write-Logline "Sending Final Log email." + $LogContents = [IO.File]::ReadAllText($LogfilePath) + $LogContentsHTML = $LogContents -Replace "`n", "
" + $Body = "Hello KACE Team,

The backup process for server $ServerPath has been completed.

Please review the full attached log

Full Logs:

$LogContentsHTML

" + #$Body += $LogContents + #echo $ErrCt + $Subjectvar = "KACE SMA Backup Log" + $Subject = [string] $Subjectvar + Send-MailMessage -To $EmailTo -from $EmailFrom -Subject $Subject -BodyAsHtml $Body -Port 25 -Priority: High -Attachment $LogFilePath } - function Goto-Error-Exit ($ErrorString) { Write-Logline "Encountered Fatal Error. Sending Error Email and exiting." Write-Logline $ErrorString @@ -500,7 +510,9 @@ If($DeletedIncrFile -ne $true -and $DeletedBaseFile -ne $true){ If($ErrCt -gt 0){ Send-Error-Email $ErrorText } - +If($ErrCt -eq 0){ + Send-Log-Email $LogText +} #Copy log file to network/backup share if ( -not ( Test-Path $BackupLocation"Logs" -PathType Container )) { New-Item -Path $BackupLocation"Logs" -ItemType directory