我正在使用Send-MailMessage
发送一堆文件作为附件
有些文件存在,有些不存在,因此,如果缺少其中一个文件,则Send-MailMessage
失败。
如果文件丢失,有什么办法可以处理Test-Path
并清理$attachments
?
我的代码:
$Attachments = "$longlist_file","$PingList_File","$quicklist_file", `
"$nConf_import_host_file","$nConf_import_service_file", `
"$nconf_export_host_file","$nconf_export_service_file"
# Sending mail
send-mailmessage -to $ToAddress -from $FromAddress -smtpserver $SMTPServer `
-subject $MessageSubject -Body $MessageBody -Attachments $Attachments
最佳答案
大概
$Attachments = $longlist_file","$PingList_File","$quicklist_file", `
"$nConf_import_host_file", "$nConf_import_service_file", `
"$nconf_export_host_file", "$nconf_export_service_file" `
| Where-Object { Test-Path $_ }
关于variables - 发送邮件消息失败,因为附件丢失(变量变乱),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8934099/