Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于阅读outlook邮件的Powershell_Powershell_Outlook - Fatal编程技术网

用于阅读outlook邮件的Powershell

用于阅读outlook邮件的Powershell,powershell,outlook,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.olDefaultF

我一直试图在收件箱中阅读带有特定主题的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,并将配置文件密码作为参数。我希望配置文件的密码在没有密码提示的情况下通过脚本发送。

请指出必须进行的更改。

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

根据密码字段的说明,
Logon()
方法已被弃用,在现代系统配置中不起作用。如果您使用的是默认配置文件,则可以删除
Logon()
方法,但您可能需要进行更多的阅读,以确保此方法适用于您的特定用例。