web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Simple AX / Powershell: seeking file in...

Powershell: seeking file in a folder and send by smtp relay mail

Daniele Ferraretto Profile Picture Daniele Ferraretto

the title of this post explain all. Useful if you have to sent last lofg error file and so on

insert in a .ps1 file and schedule with task scheduler of

$dir = “”
$latest = Get-ChildItem -Path $dir | Sort-Object LastAccessTime -Descending | Select-Object -First 1
$latest.Fullname

$attachment = $latest.Fullname

if($attachment)
{
$emailSmtpServer = “”
$emailSmtpServerPort = “”
$emailSmtpUser = “”
$emailSmtpPass = “”
$EmailFrom = “”
$EmailTo = @(“”, “second mail recipient”)
$EmailBody = “”
$EmailSubject = “”

try
{
Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -body $EmailBody -SmtpServer $emailSmtpServer -Attachments $attachment
}
catch
{

}
start-sleep -s 20
Remove-Item $attachment
}



This was originally posted here.

Comments

*This post is locked for comments