#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))
}
}
}
任何人都可以帮助这个上面的脚本,它实际上运行并写入主机,但附件不会出现在驱动器文件夹中,因为他们应该,任何想法?
由于
答案 0 :(得分:0)
假设您刚刚复制了脚本并且没有注意到它只是保存附件,其中名称包含yyyyMMdd格式的当前日期,如果您想要保存所有附件,这就是您要做的事情:
#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))
}
}