【问题标题】:Table format of the status of the scheduled tasks in Windows scheduler in PowershellPowershell中Windows调度程序中计划任务状态的表格格式
【发布时间】:2019-02-13 07:05:52
【问题描述】:

我正在尝试通过电子邮件获取有关 Windows 计划程序中计划任务状态的信息。

我更喜欢表格格式的输出。目前我将其输出为 csv 并通过电子邮件附加。

当前代码:

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 )

我知道我可以用这个:

Get-ScheduledTask -TaskPath "\" | Get-ScheduledTaskInfo | Out-String

但这会以字符串格式输出数据,但我希望它是表格格式。

【问题讨论】:

    标签: powershell


    【解决方案1】:

    您可以尝试使用 cmdlet“Format-Table”。 对于你的命令试试这个:

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

    您可以在以下参考资料中找到更多信息:

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

    【讨论】:

    • Format-Table 将输出限制为屏幕宽度,管道到| Format-Table -AutoSize | Out-String -Stream -Width <int> 以克服这个问题。 this answer from mklement0中的其他解决方案
    • 给我这个错误: '
    • 您需要在命令中将 替换为整数,例如:Get-ScheduledTask -TaskPath "\" | Get-ScheduledTaskInfo |格式表-AutoSize | Out-String -Stream -Width 80
    • 它仍然没有以表格格式出现。输出在行中。我需要一张合适的桌子..
    猜你喜欢
    • 2017-08-22
    • 1970-01-01
    • 2019-03-24
    • 2013-08-22
    • 1970-01-01
    • 1970-01-01
    • 2015-01-04
    • 2014-12-28
    • 2012-06-27
    相关资源
    最近更新 更多