在 Powershell 中创建 Outlook 规则时出错
Error creating Outlook Rules in Powershell
我一直在摆弄 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)
而不是定义 $junk = $routlook.GetDefaultFolder(23)
但是我当然没有在问题中提供此信息,因为我认为它似乎不相关,因为我的脚本中没有其他内容会导致此文件夹的定义方式出现问题。
我一直在摆弄 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)
$junk = $routlook.GetDefaultFolder(23)
但是我当然没有在问题中提供此信息,因为我认为它似乎不相关,因为我的脚本中没有其他内容会导致此文件夹的定义方式出现问题。