我有這個 PS 腳本,它發送帶有附件的電子郵件,我將在 SQL Server 作業中運行。
Send-MailMessage
-From 'User01 <user01@fabrikam.com>'
-To 'User02 <user02@fabrikam.com>', 'User03 <user03@fabrikam.com>'
-Subject 'Sending the Attachment'
-Body "Forgot to send the attachment. Sending now."
-Attachments c:\temp\ibn\IBN_1_56_4960135.txt
-Priority High
-SmtpServer 'smtp.fabrikam.com'
此檔案為空時為 768 位元組,因此我嘗試向其添加一個 powershell 腳本,該腳本檢查并且如果此檔案大小為該大小或更小,則不發送電子郵件,因此檔案為空。
請問有什么建議嗎?
我在網上找到了這個,但作為一個 Powershell 新手,它沒有說明我需要在腳本中的哪個位置放置它或如何放置,因為它沒有在文章中說明。
get-item c:\temp\ibn\IBN_1_56_4960135.txt | foreach -process {if ( $_.length -gt 0 ) { send mail here }}
謝謝!
uj5u.com熱心網友回復:
只需使用您發現的內容來環繞Send-Mail.
Get-ChildItem -File -Path 'C:\path\to\myfile.txt' |
ForEach-Object {
if ($_.Length -gt 768) {
Send-MailMessage
-From 'User01 <[email protected]>'
-To 'User02 <[email protected]>', 'User03 <[email protected]>'
-Subject 'Sending the Attachment'
-Body "Forgot to send the attachment. Sending now."
-Attachments $_.FullName
-Priority High
-SmtpServer 'smtp.fabrikam.com'
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/436913.html
