使用PowerShell保存Outlook附件

时间:2019-01-25 12:41:17

标签: powershell outlook powershell-v4.0

我正在努力寻找解决方案,因此希望有人可能遇到了这个问题。我有一个PowerShell脚本来保存所有Outlook附件以自动执行日常检查。手动运行可以很好地工作,但是它可以在一夜之间在桌面上运行,因此由于设备被锁定而失败。

我知道excel可以通过将可见性设置为false来工作,但是找不到Outlook的类似选项。任何帮助将不胜感激!

$outlook = New-Object -comobject outlook.application
$inbox = $outlook.GetNamespace("MAPI")
$find = $inbox.GetDefaultFolder(6)

$filepath = "$InputDir"
$find.Items| foreach {
 $SendName = $_.SenderName
   $_.attachments|foreach {
    Write-Host $_.filename
    $name = $_.filename
    If( -Not (Test-Path -Path "$InputDir\$name")) {
    If ($name.Contains("txt")) {
    $_.saveasfile((Join-Path $filepath "$name"))
       }
    }
  }
 }

1 个答案:

答案 0 :(得分:0)

您应该使用EWS(Exchange Web服务)。

这是一个很好的示例,说明了如何直接(不使用Outlook)查询Exchange以检索项目。尽管值得,但它有些复杂,因为它可以作为计划任务在尚未登录的计算机上运行:

https://gsexdev.blogspot.com/2010/01/writing-simple-scripted-process-to.html