powershell - 如何找到 Outlook 的路径,以便我可以发送带有脚本的电子邮件
问题描述
我创建了一个 powershell 脚本来使用任务计划程序自动发送 csv 文件。我觉得我的路径好像犯了一个愚蠢的错误,因为什么都没有发送。
我已经测试了下面的脚本。
if($args.Count -lt 1)
{
Write-Host "Use: SendMail.ps1 <"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Outlook 2010.lnk">"
Write-Host
Write-Host "<"C:\CSV">"
Write-Host
exit
}
$FullPath=$args[0]
#Get an Outlook application object
$o = New-Object -com Outlook.Application
$mail = $o.CreateItem(0)
#2 = High importance message
$mail.importance = 2
$mail.subject = "CSV File"
$mail.body = "Here is the CSV file."
#separate multiple recipients with a ";"
$mail.To = <---->
#$mail.CC = <OTHER RECIPIENT 1>;<OTHER RECIPIENT 2>
# Iterate over all files and only add the ones that have an .csv extension
$files = Get-ChildItem $FullPath
for ($i=0; $i -lt $files.Count; $i++) {
$outfileName = $files[$i].FullName
$outfileNameExtension = $files[$i].Extension
# if the extension is the one we want, add to attachments
if($outfileNameExtension -eq ".csv")
{
$mail.Attachments.Add($outfileName);
}
}
$mail.Send()
# give time to send the email
Start-Sleep 20
# quit Outlook
$o.Quit()
#end the script
exit
我认为以下是不正确的:
Write-Host "Use: SendMail.ps1 <"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Office\Microsoft Outlook 2010.lnk">"
但我不确定路径应该是什么。
解决方案
路径应该是这样的:
C:\Program Files (x86)\Microsoft Office\root\Office16\Outlook.exe
此链接有一些方法可以找到正在运行的进程的可执行文件的路径:
推荐阅读
- tensorflow - 如何决定卷积层的过滤器?
- java - jfreechart-fx 1.0.1 图表是否可以与 fxgraphics2d 构建和呈现的图像交互,或者只是一个图像?
- javascript - 从 Three.js 中的缓冲区(不是路径)加载 STL
- fiware-orion - 如何将历史数据插入固件(日期正确)?
- performance - Jmeter :- 在并发线程中按顺序运行一组采样器
- python - 如何将时间数据转换为数值?
- angular - 在一个 ts 文件中使用多个加载器服务
- javascript - 使用 javascript(无意)打开移动应用程序(如果已安装)
- python - 创建一个填写标准 Python + Django 代码中的字段的表单
- jquery - 检查代码是否符合 jquery 3.x 的简单方法?