仅当文件不为空或大于特定大小时才使用 powershell 发送电子邮件
我有这个 PS 脚本,它发送一封带有附件的电子邮件,我将在 SQL Server 作业中运行该脚本。
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 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 }}
谢谢你!
I have this PS script that sends an email with an attachment that i will be running in a SQL server job.
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 c:\temp\ibn\IBN_1_56_4960135.txt
-Priority High
-SmtpServer 'smtp.fabrikam.com'
This file when empty will be 768bytes so i am trying to add a powershell script to it that checks and does not send an email if this file is this size or less, hence, file is empty.
Any suggestions please?
I found this online but being a Powershell novice it does not say where in the script i need to put it or how to as it did not say in the article.
get-item c:\temp\ibn\IBN_1_56_4960135.txt | foreach -process {if ( $_.length -gt 0 ) { send mail here }}
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用您找到的内容来包裹
Send-Mail
。Just use what you found to wrap around the
Send-Mail
.