Forum Discussion
kdvbhuvankumar
May 12, 2020Copper Contributor
How to send email
Hi All, I am new to PS and i need a email message where it sends me by identifying recent file names with date and time in particular folder on the server below is the simple commands i set in t...
Manfred101
May 14, 2020Iron Contributor
kdvbhuvankumar Almost there my friend! Check the script below. I hope it helps you take the next step!
Grtz, Manfred de Laat
# Get the Files
$items = Get-ChildItem -path D:\TFTP-Root | Where-Object {$_.LastWriteTime -gt (Get-Date).AddDays(-1)}
# Create a mailbody
$mailbody = ""
foreach($item in $items){
$mailbody += $mailbody + "File: " + $item.FullName + "`n" + "Size (KB): " + $item.Length + "`r`n`n"
}
# Add the mailbody
Send-MailMessage -To 'xxxxx@gmail.com' -SmtpServer 'smtp.com' -Subject 'Files and Sizes' -Body $mailbody -From "yyyyy@gmail.com"