【发布时间】:2016-12-27 05:39:11
【问题描述】:
我一直在尝试阅读收件箱中包含特定主题的 Outlook 邮件,并下载与该特定主题相关的附件。 这是我用过的powershell脚本
$filepath = “C:\folder”
$filter="[Subject]=Test Powershell"
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)")
}
}
但是,在创建 Outlook MAPI 对象后,系统提示我手动提供配置文件密码,即使我已添加 $namespace.Logon 并将配置文件密码作为参数。我希望在没有密码提示的情况下通过脚本发送配置文件的密码。
请指出为此必须做出的改变。
【问题讨论】:
-
根据The Documentation,
Logon()方法的密码字段已被弃用,并且不适用于现代系统配置。看来,如果您使用的是默认配置文件,则可以删除Logon()方法,但您可能需要做更多阅读以确保此方法适用于您的特定用例。
标签: powershell outlook