OUTLOOK正确地重新解释“纯文本”

时间:2017-04-27 19:35:36

标签: powershell email outlook office365

我想知道是否有人回答了将Write-Host的输出输入电子邮件正文的问题。我了解到Write-Host只显示在控制台上,因此不起作用。现在我被困住了,需要一些方向。这是我到目前为止所拥有的。

Set-ExecutionPolicyunrestricted

$computerSystem = Get-CimInstance CIM_ComputerSystem
$computerBIOS = Get-CimInstance CIM_BIOSElement
$computerOS = Get-CimInstance CIM_OperatingSystem
$computerCPU = Get-CimInstance CIM_Processor
$computerHDD = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
$computerip = Invoke-RestMethod http://ipinfo.io/json | Select -exp ip
Clear-Host


$Body = @(
"System Information for: " + $computerSystem.Name
"Manufacturer: " + $computerSystem.Manufacturer
"Model: " + $computerSystem.Model
"Serial Number: " + $computerBIOS.SerialNumber
"CPU: " + $computerCPU.Name
"HDD Capacity: "  + "{0:N2}" -f ($computerHDD.Size/1GB) + "GB"
"HDD Space: " + "{0:P2}" -f ($computerHDD.FreeSpace/$computerHDD.Size) + " 
Free 
(" + "{0:N2}" -f ($computerHDD.FreeSpace/1GB) + "GB)"
"RAM: " + "{0:N2}" -f ($computerSystem.TotalPhysicalMemory/1GB) + "GB"
"Operating System: " + $computerOS.caption + ", Service Pack: " + 
$computerOS.ServicePackMajorVersion
"IP Address:" + $computerip
"User logged In: " + $computerSystem.UserName 
"Last Reboot: " + $computerOS.LastBootUpTime
) -join "`r`n  `n"
write-host $body


$secpasswd = ConvertTo-SecureString “password” -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential 
(“support@email”, $secpasswd)

Send-MailMessage -To "support@email.com" -SmtpServer "smtp.office365.com" -
Credential $mycreds -UseSsl "Backup Notification" -Port "587" -Body $body -
From "support@email.com" -BodyAsHtml

到目前为止这个工作,我只需要稍微清理一下输出。我认为这是一个问题,OUTLOOK正确地重新解释“纯文本” - 因为Outlook试图为你“思考”并删除它认为过多的换行符。

电子邮件输出如下所示:

系统信息:APL-PBC4Y9W制造商:LENOVO型号:2349OK7序列号:PBC4Y9W CPU:Intel(R)Core(TM)i5-3320M CPU @ 2.60GHz HDD容量:298.09GB硬盘空间:57.68%免费(171.93) GB)RAM:7.70GB操作系统:Microsoft Windows 7专业版,Service Pack:1 IP地址:111.111.11.1用户登录:GEINDSYS-AMER \ 502706436 Last Reboot:04/26/2017 08:22:07

我希望将所有项目都放在新的一行上。

0 个答案:

没有答案