【发布时间】:2014-04-29 00:43:04
【问题描述】:
我有一个脚本可以读取 Outlook 文件夹中的电子邮件,选择最近收到的电子邮件,并将其附件保存到目录中。
它无法正常工作 - 如果我在运行脚本之前第一次打开 Outlook,它似乎只知道要接收哪封电子邮件 - 否则,它认为最近收到的电子邮件是我上次收到的电子邮件上次打开 Outlook。
有没有办法在脚本提示扫描之前提示 Outlook 刷新?
我的代码如下:
$filepath = $args[0]
$account = $args[1]
<#
#file path
$filepath = "I:\folder"
$account = "account@host.com"
#>
#set outlook to open
$o = New-Object -comobject outlook.application
$n = $o.GetNamespace(“MAPI”)
$Account = $n.Folders | ? { $_.Name -eq $account };
$Inbox = $Account.Folders | ? { $_.Name -match 'Inbox' };
$Data = $Inbox.Folders | ? { $_.Name -match 'Data' };
$f = $Data.Folders | ? { $_.Name -match 'MyTargetFolder' };
$email = $f.Items | Sort-Object ReceivedTime -Descending | Select-Object -First 1
# Log the email we are looking for, and mention attachments if they exist.
Write-Output "Last email received at $($email.receivedtime), attached file(s) are: (if any)"
$email.attachments | %{Write-Output $_.filename}
# If the email has at least one attachment, save them to the filepath.
if ($email.attachments.count -gt 0) {
$email.attachments | %{$_.saveasfile((join-path $filepath $_.filename))}
} else {
Write-Output "Latest email at $($email.receivedtime) has no attachments!"
}
【问题讨论】:
标签: powershell outlook etl