2012-10-18 40 views
0

我有一個powershell腳本,它使用Write-Output來顯示每個循環的結果。 我需要通過電子郵件發送的輸出和以前用VB使用sendemail.exe如下通過電子郵件發送PowerShell輸出

cscript //nologo script.vbs 2>&1 | sendEmail.exe -t [email protected] -u "subject blah" -f [email protected] -s smtpserver1.mail.co.uk 

我無法得到使用PowerShell這方面的工作,當我跑我的.ps1腳本它寫輸出到當前控制檯爲完成這一任務,不會將其傳送到sendemail.exe應用程序。我是否需要一個不同的cmdlet,或者將電子郵件功能寫入腳本更簡單嗎?

回答

3

爲什麼不使用此本機cmdlet,如果您使用的是PowerShell v2或v3?

send-mailmessage

5

不要sendmail.exe在所有使用PowerShell使用。在PowerShell 2.0及更高版本中,在腳本中使用Send-MailMessage。將你的「輸出」捕獲到一個變量中,並通過-Body參數傳入。