我想從每天收到的電子郵件中提取並保存.xls文件。我設置了一個規則,將電子郵件保存在收件箱中特定子文件夾的Outlook郵箱中。從特定Outlook文件夾中提取.xls文件的PowerShell腳本
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))
}
}
}
感謝您的建議,但在原來的文章中提到,'ToExtract'是更新了答案Inbox' –
的'子文件夾內的子文件夾。 –
美麗。謝謝你的幫助! –