gpt4 book ai didi

powershell - 在 Powershell 中创建 Outlook 规则时出错

转载 作者:行者123 更新时间:2023-12-03 16:34:46 25 4
gpt4 key购买 nike

我一直在摆弄 Powershell 的 Outlook 对象。我想创建 Outlook 规则并且我让它工作了。暂时搁置了这个项目。当我把它拿回来时,我无法创建 Outlook 规则。请注意,我没有更改代码中的任何内容。

代码生成Outlook规则

 $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()

错误

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("Folde ...
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : COMException

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

最佳答案

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

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

但当然我没有在问题中提供此信息,因为我认为它似乎不相关,因为我的脚本中没有其他内容会导致此文件夹的定义方式出现问题。

关于powershell - 在 Powershell 中创建 Outlook 规则时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37521975/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com