Powershell用于阅读Outlook消息

时间:2016-12-27 05:39:11

标签: powershell outlook

我一直在尝试在具有特定主题的收件箱中阅读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作为参数添加了配置文件密码。我希望通过脚本发送配置文件的密码,而无需密码提示。 请指出必须进行的更改。

1 个答案:

答案 0 :(得分:0)

Namespace.Logon不会获取Exchange邮箱的密码。它可能适用于受密码保护的PST文件,但不适用于Exchange邮箱。至少登录一次并确保"记住密码"选中复选框以确保不再提示您。