PowerShell Script to Read/Parse XML Files in a Directory

# This script is to be set on the FTP server or 

$files = Get-ChildItem $folder *.xml -recurse;
# $files = Get-ChildItem -path $folder | where {$_.Lastwritetime -lt (date).addminutes(-0)}
if ($files){
$timeStamp = Get-Date -Format g
foreach ($file in $files){
$MyXml = Get-Content $folder\$file;
# Copy files to FD
# Move file(s) into a backup folder
# Send an email to the appropriate team
$EmailFrom = "admin@kimconnect.com"
$EmailTo = "orders@kimconnect.com"
$Subject = "Incoming EDI Order(s) Received"
$Body = "Some new Purchase Order(s) has been received with this timestamp: $timeStamp.`n`nHere is the list of associated PO Number(s):`n`n$pos"
$SMTPServer = "kimconnect.mail.protection.outlook.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 465)
$SMTPClient.EnableSsl = $false
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("admin@kimconnect.com", "password");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
Posted on Categories Codes

Leave a Reply

Your email address will not be published. Required fields are marked *