I am using below code to download the attachment from email based on subject, but i am unbale to use like operater to check the subject and download, below is the code which i am using
I was tring for [Subject] like Test Powershell, but i am unable to achive this
**
$filepath = “D:\PowerShell”
$filter="[Subject]=Test Powershell"
$myNow = get-date -format "yyyy-MM-dd_hh-mm-ss"
Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
$olFolders = "Microsoft.Office.Interop.Outlook.olDefaultFolders" -as [type]
$outlook = new-object -comobject outlook.application
$namespace = $outlook.GetNameSpace("MAPI")
$namespace.Logon("profilename","mypassword",$false,$false)
$folder = $namespace.getDefaultFolder($olFolders::olFolderInBox)
#$folder.items|select *
$folder.items.Restrict($filter) |
select -Expand Attachments | % {
for ($i = $_.Count; $i; $i--) {
$_.Item($i).SaveAsFile("$filepath\$($_.Item($i).FileName)")
}
}
**