【发布时间】:2014-03-02 12:13:17
【问题描述】:
我想从我每天收到的电子邮件中提取并保存一个 .xls 文件。我设置了一个规则,将电子邮件保存在 Outlook 邮箱中,位于收件箱的特定子文件夹中。
Outlook 文件夹结构如下所示:
-> Inbox
--> Data (subfolder of "Inbox")
---> ToExtract (subfolder of "Data")
我需要从“ToExtract”文件夹中提取 .xls 文件。
I found a script 为我完成了大部分工作,但它需要用户监督脚本并手动选择要搜索的 Outlook 文件夹。我需要更改脚本,使其仅指向“ToExtract”子文件夹。
代码如下。它工作正常,但我需要修改 pickfolder() 部分。
#file path
$filepath = “c:\test\”
#set outlook to open
$o = New-Object -comobject outlook.application
$n = $o.GetNamespace(“MAPI”)
#you'll get a popup in outlook at this point where you pick the folder you want to scan
$f = $n.pickfolder()
#date string to search for in attachment name
$date = Get-Date -Format yyyyMMdd
#now loop through them and grab the attachments
$f.Items | foreach {
$_.attachments | foreach {
Write-Host $_.filename
$a = $_.filename
If ($a.Contains($date)) {
$_.saveasfile((Join-Path $filepath $a))
}
}
}
【问题讨论】:
标签: excel powershell outlook powershell-2.0 etl