Skip to content

Instantly share code, notes, and snippets.

@VibhuKuchhal
Created May 29, 2018 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VibhuKuchhal/d82b0da4424c4d979c1fae266e5f820d to your computer and use it in GitHub Desktop.
Save VibhuKuchhal/d82b0da4424c4d979c1fae266e5f820d to your computer and use it in GitHub Desktop.
$migrationDataFolder = '\\masterterminal\c$\AutomatedMigrationData'
$mailFolder = 'mails'
$inputFolder = 'input'
$processingFolder = 'processing'
$finalFolder = 'final'
function SendMail{
Param(
[string] $subject,
[string] $body
)
#Write-Host $LibraryName
#Write-Host $startTime
#Write-Host $endTime
#Write-Host $subject
#Write-Host $body
[string[]]$recipients = "vibhu.kuchhal@somedomain.com.au","vibhu.kuchhal@someotherdomain.com.au"
Send-MailMessage -To $recipients -Subject $subject -BodyAsHtml $body -SmtpServer "smtp.yourSMTP.com.au" -From "MigrationAccount@yourdomain.com.au" -UseSsl -Port 25
}
$inputpath = $migrationDataFolder + '\' + $mailFolder + '\' + $inputFolder
$processingPath = $migrationDataFolder + '\' + $mailFolder + '\' + $processingFolder
$finalPath = $migrationDataFolder + '\' + $mailFolder + '\' + $finalFolder
while($true)
{
$unprocessedRecords = Get-ChildItem -Path $inputpath
foreach($item in $unprocessedRecords){
Move-Item -Path $item.FullName -Destination $processingPath
$effectivepath = $processingPath + '\' + $item.Name
$processingitem = Get-Item -Path $effectivepath
$mail = Import-Csv -Path $effectivepath
SendMail -subject $mail.Subject -body $mail.Body
Move-Item -Path $processingitem -Destination $finalPath
}
Write-Host "Sleeping for 10 seconds"
Start-Sleep 10
}
#Exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment