Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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
powershell outlook自动化命名空间_Powershell_Automation_Outlook_Activexobject - Fatal编程技术网

powershell outlook自动化命名空间

powershell outlook自动化命名空间,powershell,automation,outlook,activexobject,Powershell,Automation,Outlook,Activexobject,我正在使用javascript和activex通过IE中的EntryID自动打开公用文件夹,但遇到了一些错误。为了调试,我将其重新编写为powershell脚本 $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.GetFold

我正在使用javascript和activex通过IE中的EntryID自动打开公用文件夹,但遇到了一些错误。为了调试,我将其重新编写为powershell脚本

$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
调用带有“2”参数的“GetFolderFromID”时出现异常:“消息传递接口返回未知错误。如果问题仍然存在,请重新启动Outlook。”
位于G:\scripts\outlook.ps1:5 char:25
+$f=$ns.GetFolderFromIDGetFolderFromID()需要两个参数:所需文件夹的EntryID和StoreID

此代码没有错误,显示选定PublicFolder的outlook:

$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
行是否已注释。

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

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

GetFolderFromID()只需要一个参数。第二个参数存储ID是可选的@Pete好的,我没有读msdn,只是看了一下方法的定义。很高兴知道!我特别想打开一个我有特定EntryID的文件夹,而不是存储库的底部。为了清楚起见,我更新了我的问题。