【问题标题】:format txt file when sending powershell email发送PowerShell电子邮件时格式化txt文件
【发布时间】:2013-12-18 23:54:50
【问题描述】:

我必须将 powershell 脚本的输出发送到 Outlook\外部电子邮件,到达目的地时看起来真的很糟糕。 任何想法如何格式化它以使其看起来像原来的一样?

这是我原来的 .txt 的样子:

这里有一些文字

Directory: C:\Users\xxx\Desktop

-a---         12/6/2013   2:31 PM      30823 diagram.docx
-a---        12/16/2013   2:17 PM       2002 Microsoft Outlook 2010.lnk
-a---        12/10/2013   2:25 PM       1576 new vlans.txt
-a---        12/12/2013   9:39 AM         59 pass.txt
-a---        12/11/2013   1:57 PM      14764 vlans for Q9.xlsx
-a---        12/10/2013   2:19 PM     182784 _Release Request Form V12.doc
Total size GB
--------------
0.450272973626852  

电子邮件:

这是我使用的代码:

 'New-Item c:\users\xxx\desktop\pwr -type directory
echo "Good morning gentlemen, below are this week's  bakups report!" > c:\users\xxx\desktop\pwr\bkp.txt

'(Get-ChildItem -Path C:\Users\xxx\Desktop\*.*  | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-10) }) >> c:\users\xxx\desktop\pwr\bkp.txt

'(Get-ChildItem -Path C:\Users\xxx\Desktop\*.*  | ? {$_.LastWriteTime -gt (Get-Date).AddDays(-10) }).Count > c:\users\xxx\desktop\pwr\tmp.txt

'Get-ChildItem c:\users\xxx\desktop -recurse | Measure-Object -property length -sum|ft @{Name="Total size GB "; Expression={$_.Sum / 1GB};align="left"} >> c:\users\xxx\desktop\pwr\bkp.txt 

'gwmi win32_volume -Filter 'drivetype = 3' | select driveletter, label, @{LABEL='GB freespace';EXPRESSION={$_.capacity / 1gb }} >> c:\users\xxx\desktop\pwr\tmp.txt
Get-Date -Format "dd/MM/yyyy" >> c:\users\xxx\desktop\pwr\tmp.txt


$ol = New-Object -comObject Outlook.Application  
$mail = $ol.CreateItem(0)  
$Mail.Recipients.Add("email@domain.com")  
$mail.Subject = "Weekly PME Backups $((get-date -format "dd/MM/yyyy"))" 
$Mail.Body = (Get-content "C:\Users\xxx\Desktop\pwr\bkp.txt")  
$Mail.Send()

谢谢! 西普里安

【问题讨论】:

    标签: email formatting powershell-2.0


    【解决方案1】:

    终于弄明白了 :) 测试并使用 Outlook

    $ol = New-Object -comObject Outlook.Application  
    $mail = $ol.CreateItem(0)  
    $Mail.Recipients.Add("email@domain.com")  
    $mail.Subject = "Weekly  Backups $((get-date -format "dd/MM/yyyy"))" 
    $Mail.Body = (Get-content "C:\Users\xxx\Desktop\pwr\bkp.txt")    
    $Mail.body = $body -join "`n"
    $Mail.Send()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-08
      • 2015-12-24
      • 2021-05-09
      • 1970-01-01
      • 2010-09-25
      • 2015-03-06
      • 2017-12-19
      • 2017-04-18
      相关资源
      最近更新 更多