Michael Leonard
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\bo t1-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\bo t2-2014
this is the code we have so far:
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\bo
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\bo
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
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This script needs Outlook, and accesses the mailbox and folder as noted.
ASKER
thanks Qlemo, sorry for the delay in responding back. excellent script.
S.
S.
ASKER
how can we target this script to one specific mailbox? sorry forgot to put that in my initial question.
S.