在Powershell中创建Outlook规则时出错 [英] Error creating Outlook Rules in Powershell

查看:95
本文介绍了在Powershell中创建Outlook规则时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在弄乱Powershell的Outlook对象.我想创建Outlook规则,并使其起作用.将项目搁置一段时间. 备份后,我无法创建Outlook规则.请注意,我没有更改代码中的任何内容.

I've been messing around with Outlook objects for Powershell. I wanted to create Outlook Rules and I got it to work. Layed the project aside for a while. When I picked it back up I was unable to create Outlook rules. Note that I did NOT change anything in the code.

 $rules = $ol.Session.DefaultStore.GetRules()

 $rule = $rules.Create("spamfilter",[Microsoft.Office.Interop.Outlook.OlRule Type]::olRuleReceive)

    $condition = $rule.Conditions.SenderAddress
    $condition.Enabled = $true
    $condition.Address = @("<sender>")
    $action = $rule.Actions.MoveToFolder
    $action.Enabled = $true

    [Microsoft.Office.Interop.Outlook._MoveOrCopyRuleAction].InvokeMember("Folder",[System.Reflection.BindingFlags]::SetProperty,$null,$action,$junk)

    $rules.Save()

错误

使用"5"参数调用"InvokeMember"的异常:未找到成员.(来自HRESULT的异常:0x80020003(DISP_E_MEMBERNOTFOUND))" 在第22行char:5

Exception calling "InvokeMember" with "5" argument(s): "Member not found. (Exception from HRESULT: 0x80020003 (DISP_E_MEMBERNOTFOUND))" At line:22 char:5

  • [Microsoft.Office.Interop.Outlook._MoveOrCopyRuleAction] .InvokeMember(折叠...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo:未指定:(:) [],MethodInvocationException
    • FullyQualifiedErrorId:COMException
    • [Microsoft.Office.Interop.Outlook._MoveOrCopyRuleAction].InvokeMember("Folde ...
    • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
      • FullyQualifiedErrorId : COMException

      请有人帮帮我.似乎是什么问题?我迷路了,谢谢.

      Someone please help me. What seems to be the issue? I'm lost, thanks.

      推荐答案

      我发现了问题.我使用赎回Outlook库定义了$junk变量. 这样,它不是合法的MAPI对象,因此不会被识别为有效参数.

      I found the problem. I defined the $junk variable using Redemption outlook library. This way it's not a legit MAPI object so it doesn't get recognized as a valid parameter.

      我没有使用$junk = $ol.Session.DefaultStore.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderJunk)

      但是,我当然没有在问题中提供此信息,因为我认为它似乎无关紧要,因为脚本中的其他内容都没有影响此文件夹的定义方式.

      But ofcourse I did not provide this information in the question because I didn't think it seemed relevant as nothing else in my script makes a problem of how this folder is defined.

      这篇关于在Powershell中创建Outlook规则时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆