Posted On March 31, 2019

PowerShell Script to Read/Parse XML Files in a Directory

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell Script to Read/Parse XML Files in a Directory
# This script is to be set on the FTP server or 

$folder = '\\FTPSERVER05\SFTP\EDI\INCOMING';
$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;
$pos+=$MyXml.PurchaseOrders.PurchaseOrder.OrderHeader.PONumber;
}
# Copy files to FD
copy \\FTPSERVER05\SFTP\EDI\INCOMING\*.xml \\FILESERVER01\EDI\INTERFACES\ORDERS.FTP.IN
# Move file(s) into a backup folder
robocopy \\FTPSERVER05\SFTP\EDI\INCOMING \\FTPSERVER05\SFTP\EDI\BACKUP\INCOMING /E /R:10 /NP /IS /IT /MOV
# Send an email to the appropriate team
$EmailFrom = "[email protected]"
$EmailTo = "[email protected]"
$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("[email protected]", "password");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
}

Leave a Reply

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

Related Post

How to Use Google SMTP Relay with Sendmail

Check to see if TLS is enabled:# sendmail -d0.1 -bv rootMake a certs directory:# mkdir…

PowerShell: Hobocopy Backup Software

# hobocopy-backup.ps1# Note: this is a quick snippet to demonstrate the use of this utility.#…

PowerShell: Get OU of a User & Get All Users In an OU

function getUserOu($username){ if(!(get-module activedirectory -ea SilentlyContinue)){ $osType=switch ((Get-CimInstance -ClassName Win32_OperatingSystem).ProductType){ 1 {'client'} 2 {'domaincontroller'} 3…
Other project: DragonCoin.com