如何找到Outlook的路径,以便我可以发送带有脚本的电子邮件

时间:2019-05-08 17:07:34

标签: powershell outlook

我创建了一个powershell脚本,以使用Task Scheduler自动发送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">"

但是我不确定路径应该是什么。

1 个答案:

答案 0 :(得分:0)

路径应类似于:

C:\Program Files (x86)\Microsoft Office\root\Office16\Outlook.exe

此链接提供了几种方法来查找正在运行的进程的可执行文件的路径:

http://www.softwareok.com/?seite=faq-Windows-10&faq=152