Hello experts,
I am monitoring a specific folder location in a server, if we find files, PowerShell should drop an email to the users with the list of files available on the location. I am using below code and it is somewhat working fine however the format is little weird:
$dirlist = (ls -Path C:\TEMP\temp).Name
if ($dirlist -ne $null)
{
Write-Host “Dear User,
n
n Script has finished but there are still few files left over as below:”
$From = “xxxxxx@.xx.com”
$To = “xxxxxx@.xx.com”
$dirlist.ToString()
$Subject = ‘Files Found’
$Body = "Dear User,
n
n Script has finished but there are still few files left over as below: n
n "
$body += $dirlist
Send-MailMessage -From $From -to $To -Subject $Subject `
-Body $Body -SmtpServer $SMTPServer -port $SMTPPort
}
Output is as follow:
Dear User,
Script has finished but there are still few files left over as below:
New Text Document - Copy (2).txt New Text Document - Copy (3).txt New Text Document - Copy (4).txt New Text Document - Copy.txt New Text Document.txt
==============
How do I make sure it lists the file in Tabular format but not on a single line, Would appreciate someone can help in it