【问题标题】:Outlook Subfolder Attachment saving - powershell COMOutlook 子文件夹附件保存 - powershell COM
【发布时间】:2016-03-24 20:02:02
【问题描述】:
#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))
      }
  }
}

任何人都可以帮助处理上述脚本,它实际上运行并写入主机,但附件没有出现在驱动器文件夹中,有什么想法吗?

谢谢

【问题讨论】:

    标签: powershell outlook


    【解决方案1】:

    假设您刚刚复制了脚本并且没有注意到它只是保存名称包含当前日期的附件,格式为 yyyyMMdd,如果您想保存所有附件,您会这样做:

    #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()
    
    #now loop through them and grab the attachments
    $f.Items | foreach {
        $_.attachments | foreach {
        Write-Host $_.filename
        $a = $_.filename
        $_.saveasfile((Join-Path $filepath $a))
      }
    }
    

    【讨论】:

    • 谢谢,毕竟我没有删除无用的获取日期。我本质上希望将电子邮件发送到子文件夹,但是每个附件在到达子文件夹时都会打印出来,有没有办法做到这一点?
    • @Royston 我不知道,如果你能找到一种方法让 Outlook 将文件安全保存到文件夹中,你可以为目录注册一个事件处理程序并以这种方式打印它们,但你会必须自己弄清楚。不过,这超出了本主题的范围。如果我的回答解决了你的问题,记得接受。
    猜你喜欢
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-22
    • 1970-01-01
    相关资源
    最近更新 更多