如何将多个附件添加到 Powershell 电子邮件脚本 [英] How do I add multiple attachments to Powershell email script

查看:91
本文介绍了如何将多个附件添加到 Powershell 电子邮件脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个脚本来侦听特定文件夹中的新文件.当它找到一个新文件时,我想通过电子邮件发送该文件,以及我明确定义的另一个文件.这是一些代码:

I am running a script to listen for new files in a specific folder. When it finds a new file I want email that file, and another file that I'm explicitly defining. here's a bit of code :

    $Report = "C:\somefolder\somefile.xml"
    $AnotherReport = "C:\somefolder\someotherfile.xml"

稍后我想做这样的事情

    Send-MailMessage -Attachments $Report,$AnotherReport

我想从不同位置添加多个附件.这样做的正确语法是什么?

I want to add more than one attachment from different locations. What is the proper syntax to do that?

推荐答案

我没有测试过,你可以这样试试

I have not tested but you can try like this

#Converts to array
$Report = @("C:\somefolder\somefile.xml")
$AnotherReport = "C:\somefolder\someotherfile.xml"
$Report += $AnotherReport

Send-MailMessage -Attachments $Report

这篇关于如何将多个附件添加到 Powershell 电子邮件脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆