Hello all,
I have a PS script which is supposed to search a mailbox for a specific attachment and save the file locally. Its not working for some reason and I was hoping someone could tell me what I'm missing...
#file path
$filepath = “C:\scripts\UltiProFeed\Filetoprocess\”
#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
$Account = $n.Folders | ? { $_.Name -eq 'email-removed' };
$Inbox = $Account.Folders | ? { $_.Name -match 'Inbox' };
$f = $Inbox.Folders | ? { $_.Name -match 'ultipro' };
#date string to search for in attachment name
#$date = (get-date).AddDays(-1).ToString('yyyyMMdd')
#now loop through them and grab the attachments
$f.Items | foreach {
$_.attachments | foreach {
Write-Host $_.filename
$a = $_.filename
If ($a.Contains('AD Export of Employee Information Report')) {
$_.saveasfile((Join-Path $filepath $a))
}
}
}
ren "C:\scripts\UltiProFeed\Filetoprocess\AD Export of Employee Information report.csv" "AD Export of Employee Information Report.txt"
Thanks in advance for any advice.