Hi
I need to create a script that lists files from a folder and email to several people.
I wrote this line of code
$FileNames = Get-ChildItem -Path $failed_TXT_folder -File | Where-Object {$_.CreationTime -gt (Get-Date).AddDays(-35) }
to get a list of files from a folder defined in that variable $failed_TXT_folder with that where clause in it
I want the list of files to be 1 column to also include the $file.LastWriteTime
I know I can't simply write:
Send-MailMessage -From $from -To $emailTo -Subject $Subject -Body $FileNames -SmtpServer $Smtpserver
I think the -Body argument expects text and the elements of variable $FileNames are objects?
Thank you in advance
Gino
formatting contents in the body of email
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: formatting contents in the body of email
This will create a plain text body.
Code: Select all
$FileNames = Get-ChildItem -Path $failed_TXT_folder -File |
Where-Object {$_.CreationTime -gt (Get-Date).AddDays(-35) } |
Select Fullname, LastWriteTime |
Out-String
Re: formatting contents in the body of email
Yep!
$FileNames = Get-ChildItem -Path $failed_TXT_folder -File | Where-Object {$_.CreationTime -gt (Get-Date).AddDays(-1)} | Out-String
Thanks
GF
$FileNames = Get-ChildItem -Path $failed_TXT_folder -File | Where-Object {$_.CreationTime -gt (Get-Date).AddDays(-1)} | Out-String
Thanks
GF