带有Get-Content的奇怪的电子邮件正文格式

时间:2018-01-09 21:20:02

标签: html powershell

我正在尝试编写一个PowerShell脚本,它将运行if语句,然后将其输出到Text文件中。在一天结束时,我想读取文件并将其输出到电子邮件正文中。

我的问题是正文的格式是一个数组,而我需要它是String(对齐)。 第一张图片是常规格式,其中"时间戳"只是在上一行结束后继续运行。

Regular format

第二张照片是我使用HTML格式的时候。它看起来很漂亮,但我想知道为什么 HTML有效,但不是常规Get-content

HTML format

$emailSmtpServer = "SMTPSERVER"
$emailSmtpServerPort = "587"
$emailSmtpUser = "USER"
$emailSmtpPass = "PASS"
$emailFrom = "FROM@EMAIL.COM"
$emailTo = "TO@EMAIL.COM"
$emailMessage = New-Object System.Net.Mail.MailMessage($emailFrom, $emailTo)

$SMTPClient = New-Object System.Net.Mail.SmtpClient($emailSmtpServer, $emailSmtpServerPort)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential($emailSmtpUser, $emailSmtpPass);

<# Send Email parameter:
$SMTPClient.Send($emailMessage)
#>

# Declare Counters
$count = 0
$errorLoop = 0
$changeDetected = 0
# Declare Weekday = 1-5 || Weekend = 0,6
$Weekday = [int](get-date).DayOfWeek
# Declare hour to get 24-hour format
$hour = [int](Get-Date -Format HH)
# Exit if weekend
if ($Weekday -lt 1 -or $Weekday -gt 5) {exit}
# Compare Files
$FileA = (Get-Item "C:\Trivium\Logs\DataLogs\msrcdm_rawCDR1\msrcdm_rawCDR1_1.txt").Length
# File Path
$Log = "C:\scripts\log$(get-date -f yyyy-MM-dd).txt"
# Date Subject
$Date = "$(Get-Date -f yyyy-MM-dd)"
Write-Output $(Get-Date)"<br />" >> $Log
Write-Output "TimesStamp = $TimeStamp | FileA = $FileA | FileB = $fileB | Cycle = $count | Loop = Wkdy Bu<br />" >> $Log
Write-Output "TimesStamp = $TimeStamp | FileA = $FileA | FileB = $fileB | Cycle = $count | Loop = Wkdy Bu<br />" >> $Log
Write-Output "TimesStamp = $TimeStamp | FileA = $FileA | FileB = $fileB | Cycle = $count | Loop = Wkdy Bu<br />" >> $Log
Write-Output "TimesStamp = $TimeStamp | FileA = $FileA | FileB = $fileB | Cycle = $count | Loop = Wkdy Bu<br />" >> $Log
Write-Output "TimesStamp = $TimeStamp | FileA = $FileA | FileB = $fileB | Cycle = $count | Loop = Wkdy Bu<br />" >> $Log
Start-Sleep -Seconds 600

$Weekday = [int](Get-Date).DayOfWeek    
$hour = [int](Get-Date -Format HH)      # Declare Weekday = 1-5 || Weekend = 0,6
$exit = [int](Get-Date -Format HHmm)    # Declare hour to get 24-hour format
$attachment = $log
$emailMessage.IsBodyHtml = $true
$emailMessage.Attachments.Add($attachment)
$emailMessage.Subject = "[Trivium] Daily report for $Date"
$SMTPClient.Send($emailMessage)

0 个答案:

没有答案