I am trying get the information regarding the status of the scheduled tasks in Windows Scheduler via email.
I would prefer the output to in a table format. Currently I am outputting it as a csv and attaching it via email.
Current Code:
Get-ScheduledTask -TaskPath "\" | Get-ScheduledTaskInfo | Export-Csv -NoTypeInformation -Path C:\Lakesh\scheduledTasksResults.csv
$emailSmtpServer = "smtp.mail.outlook.com"
$emailSmtpServerPort = "587"
$emailMessage = New-Object System.Net.Mail.MailMessage
$emailMessage.From = "lakesh@outlook.com"
$emailMessage.To.Add( "lakesh@outlook.com" )
$emailMessage.Subject = "Here are my scheduled tasks"
$emailMessage.IsBodyHtml = $true
$emailMessage.Body = @"
Status of Scheduled Tasks attached.
"@
$emailMessage.Attachments.Add("C:\Lakesh\scheduledTasksResults.csv")
$SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort )
$SMTPClient.Send( $emailMessage )
I know that I could use this:
Get-ScheduledTask -TaskPath "\" | Get-ScheduledTaskInfo | Out-String
But this outputs the data in string format but i would like it to be a table format.