Link to home
Start Free TrialLog in
Avatar of Michael Leonard
Michael LeonardFlag for United States of America

asked on

need powershell assistance with extracting an attachment from an inbox

Hello, We need assistance with modifying the powershell code so that it will parse the subject line of the email, and put the attachment in a certain folder.


the shares will not match the subject line.

 so for example, the subject line of one email will be "bot1 capture metrics 1212121098"  and we need the attachment of that message to be copied to a specific share, in this case: \\domain.com\repositary\bot1-2014

 the second email may have a subject line of: "bot2 capture metrics 93438308903440343"  and we need the attachment of that message copied to a different specific share, in this case: \\domain.com\repositary\bot2-2014

this is the code we have so far:

$objOutlook   = New-Object -Com "Outlook.Application"
$objMailbox   = $objOutlook.GetNamespace("MAPI").Folders.Item("Mailbox - Docs")

$objMailbox.Folders.Item("Inbox").Items.Restrict("[UnRead] = True") | 
  select -Expand Attachments | % {
    for ($i = $_.Count; $i; $i--) {
      $_.Item($i).SaveAsFile("\\server\share\$($_.Item($i).FileName)")
      $_.Parent.Unread = $false
    }
  }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Qlemo
Qlemo
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michael Leonard

ASKER

thanks Qlemo.

how can we target this script to one specific mailbox? sorry forgot to put that in my initial question.

S.
This script needs Outlook, and accesses the mailbox and folder as noted.
thanks Qlemo, sorry for the delay in responding back. excellent script.

S.