adnankh
asked on
PowerShell Script failing
Hi Expert,
I need help here I'm using this PS script for sending email if any new files arrived in a folder, not sure why I can't get any email when adding files in folder and run the script.
I added SMTP server and use the default IP address, and port 27. I open outbond connection in firewall for port 27.
Can someone help here.
Thanks in advance
I need help here I'm using this PS script for sending email if any new files arrived in a folder, not sure why I can't get any email when adding files in folder and run the script.
Param (
[string]$Path = "D:\ABC\",
[string]$SMTPServer = "172.31.32.203",
[string]$From = "abc.efg@abc.com.au",
[string]$To = "abc.efg@abc.com.au",
[string]$Subject = "New File Uploaded to FTP Site"
)
$SMTPMessage = @{
To = $To
From = $From
Subject = "$Subject at $Path"
Smtpserver = $SMTPServer
}
$File = Get-ChildItem $Path | Where { $_.LastWriteTime -ge [datetime]::Now.AddMinutes(-1) }
If ($File)
{ $SMTPBody = "`nThe following files have recently been added/changed:`n`n"
$File | ForEach { $SMTPBody += "$($_.FullName)`n" }
Send-MailMessage @SMTPMessage -Body $SMTPBody
}
I added SMTP server and use the default IP address, and port 27. I open outbond connection in firewall for port 27.
Can someone help here.
Thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER