0

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.

lakshmen
  • 28,346
  • 66
  • 178
  • 276

1 Answers1

0

You can try using cmdlet "Format-Table". For your command try this:

Get-ScheduledTask -TaskPath "\" | Get-ScheduledTaskInfo | Format-Table -AutoSize

You can find more information on the following reference:

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/format-table?view=powershell-6

Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
  • 1
    Format-Table will limit output to screen width, pipe to `| Format-Table -AutoSize | Out-String -Stream -Width ` to overcome this. Other solutions in [this answer from mklement0](https://stackoverflow.com/a/38576389/6811411) –  Feb 13 '19 at 07:43
  • gives me this error: The '<' operator is reserved for future use. How to resolve that? – lakshmen Feb 13 '19 at 08:14
  • you need to replace with integer number in command like: Get-ScheduledTask -TaskPath "\" | Get-ScheduledTaskInfo | Format-Table -AutoSize | Out-String -Stream -Width 80 – Dharmesh Purohit Feb 13 '19 at 09:43
  • it still doesn't come out in a table format. the output is in lines. i need a proper table.. – lakshmen Feb 14 '19 at 09:29