我已经创建了一个PowerShell脚本来收集一些系统统计信息并将其发送邮件,我希望在正文中插入换行符,以便一切都不会混乱。
有人知道如何在下面的脚本中实现这一点吗?
有人知道如何在下面的脚本中实现这一点吗?
Process{
$strComputerName = (Get-WmiObject -Class Win32_ComputerSystem | Select-Object Name).Name
$strComputerModel = (Get-WmiObject -Class Win32_ComputerSystem | Select-Object Model).Model
$strSerialNumber = (Get-WmiObject -Class Win32_BIOS | Select-Object SerialNumber).SerialNumber
$strDate = Get-Date
$erroractionpreference = "SilentlyContinue"
$strSMTP = $server
$strSubject = $subject
$strBody = "Hostname: $strComputerName Model: $strComputerModel Serial: $strSerialNumber Date: $strDate"
$MailMessage = New-Object System.Net.Mail.MailMessage
$MailMessage.IsBodyHtml = $true
$SMTPClient = New-Object System.Net.Mail.smtpClient
$SMTPClient.host = $strSMTP
$Sender = New-Object System.Net.Mail.MailAddress($from, "ConfigMgr")
$Recipient = New-Object System.Net.Mail.MailAddress($to)
$MailMessage.Sender = $Sender
$MailMessage.From = $Sender
$MailMessage.Subject = $strSubject
$MailMessage.To.add($Recipient)
$MailMessage.Body = $strBody
$SMTPClient.Send($MailMessage)
}
有人试图为 $strBody 输出获取 CR,有人知道怎么做吗?
谢谢 :)