Powershell: how to format Get-Childitem for email?
You can use the ConvertTo-Html
cmdlet to do this:
get-childitem $path | select-object Name | ConvertTo-Html -fragment
It will create a nice table for you that can be sent in an HTML email. The -fragment
part removes the head and body etc. and gives only the table.
How about using the ConvertTo-Html
cmdlet? Fill in your environment info.
$path = "C:\"[string] $html = dir $path | ConvertTo-Html$smptServer = ''$to = ''$from = ''$subject = 'Test'Send-MailMessage -To $to -From $from -Body $html -BodyAsHtml -SmtpServer $smptServer -Subject $subject
EDIT - This works, but the email looks like crap. If you want it to look exactly like it does when you do a dir
in the PowerShell window use this:
[string] $html = dir $path | Select Mode, LastWriteTime, Length, Name | ConvertTo-Html