【问题标题】:powershell outlook automation namespacepowershell Outlook 自动化命名空间
【发布时间】:2012-05-23 09:51:22
【问题描述】:

我正在使用 javascript 和 activex 通过 IE 中的 EntryID 自动打开公用文件夹,并遇到了一些错误。为了调试,我将它重写为一个 power shell 脚本。

$eid = "HEX EntryID FOR PUBLIC FOLDER";

$o = new-object -com outlook.application;
$ns = $o.GetNamespace("MAPI");
#$ns #if this line is commented, error
$f = $ns.GetFolderFromID($eid)
$f.Display();

如果我完全关闭 Outlook,然后运行脚本,我会收到以下错误

Exception calling "GetFolderFromID" with "2" argument(s): "The messaging interface has   returned an unknown error. If the problem persists, restart Outlook."
At G:\scripts\outlook.ps1:5 char:25
+ $f = $ns.GetFolderFromID <<<< ($eid)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

如果我取消注释 $ns 行,一切正常,即使它再次被删除。也就是说,在我完全关闭 Outlook 之前,几乎就像 $ns com 对象在我将其输出到控制台之前并没有真正被初始化。

我想知道:

  • 为什么调用$ns 可以解决问题
  • 为什么 powershell 认为我传递了 2 个参数
  • 有没有办法实现这个解决方法 在javascript中

【问题讨论】:

    标签: powershell automation outlook activexobject


    【解决方案1】:

    GetFolderFromID() 需要两个参数:EntryID 和所需文件夹的 StoreID。

    此代码没有错误,并在选择 PublicFolder 的情况下显示前景:

    $o = new-object -com outlook.application;
    $ns = $o.GetNamespace("MAPI");
    $cp = $ns.Folders # FolderClass ComObject containing all Outlook folders, usually first is the PublicFolder
    $f = $ns.GetFolderFromID( $cp.GetFirst().EntryID ,$cp.GetFirst().StoreID )
    $f.Display();
    

    使用你的代码我做不到,$ns 行注释与否。

    【讨论】:

    【解决方案2】:

    您可以通过编程方式获取公用文件夹存储:

    $ol = New-Object -ComObject Outlook.Application
    $pf = $ol.GetNamespace("MAPI").Folders | Where-Object {$_.FolderPath -like "\\Public Folders*"}
    $pf.Display()
    

    【讨论】:

    • 我特别想打开一个我有特定 EntryID 的文件夹,而不是商店的基础。为了清楚起见,我更新了我的问题。
    猜你喜欢
    • 2013-08-10
    • 2018-02-02
    • 2010-09-16
    • 1970-01-01
    • 2011-11-19
    • 2013-11-25
    • 2014-04-13
    • 1970-01-01
    相关资源
    最近更新 更多