简体   繁体   中英

Outlook Subfolder Attachment saving - powershell COM

#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))
      }
  }
}

Can anyone help with this above script, it actually runs and writes to host but the attachments dont appear in the drive folder as they should, any ideas?

Thanks

Assuming you just copied the script and havent noticed it just saves attachements where the name contains the current date in yyyyMMdd format this is what you would do if you want to save all attachements:

#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))
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM