PowerShell脚本从特定的Outlook文件夹中提取.xls文件 [英] PowerShell script to extract .xls file from specific Outlook folder
问题描述
我想从每天收到的电子邮件中提取并保存.xls文件。我设置了一个规则,将电子邮件保存在收件箱的特定子文件夹中的Outlook邮箱中。
I want to extract and save an .xls file from an email I receive daily. I have a rule set up which saves the email in an Outlook mailbox, within a specific subfolder of the Inbox.
Outlook文件夹结构如下所示:
The Outlook folder structure looks like this:
-> Inbox
--> Data (subfolder of "Inbox")
---> ToExtract (subfolder of "Data")
我需要从ToExtract中提取.xls文件文件夹。
I need to extract the .xls file from the "ToExtract" folder.
我发现一个脚本,为我做大部分的工作,但它要求用户监督脚本,并手动选择要搜索哪个Outlook文件夹。我需要更改脚本,所以它只是指向ToExtract子文件夹。
I found a script that does most of the work for me, but it requires the user to supervise the script and manually select which Outlook folder to search. I need to change the script so it just points to the "ToExtract" subfolder.
代码如下。它工作正常,但我需要修改 pickfolder()
部分。
The code is below. It works fine, but I need to modify the pickfolder()
part.
#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))
}
}
}
推荐答案
给这个镜头。
$Account = $n.Folders | ? { $_.Name -eq 'username@domain.com' };
$Inbox = $Account.Folders | ? { $_.Name -match 'Inbox' };
$f = $Inbox.Folders | ? { $_.Name -match 'ToExtract' };
这篇关于PowerShell脚本从特定的Outlook文件夹中提取.xls文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!