Powershell获取地址列表可在PS 5.1中使用,但不能在7

问题描述

我正在尝试在Outlook中检索有关全局地址列表的信息。 它可以在Powershell 5.1中工作,但不能在7.0.3中工作。

代码为:

$Outlook = NEW-Object -comobject outlook.application
$Outlook.GetNamespace("MAPI").AddressLists("Global Address List")

PS 5.1中的输出

Application          : Microsoft.Office.Interop.outlook.applicationClass
Class                : 7
Session              : Microsoft.Office.Interop.Outlook.NameSpaceClass
Parent               : System.__ComObject
AddressEntries       : System.__ComObject
ID                   : 00000000E3FDA12B9AF86342819F3DEFE5D82FE001000000000100002F00
Index                : 2
IsReadOnly           : True
Name                 : Global Address List
AddressListType      : 0
Resolutionorder      : 1
IsInitialAddressList : True
PropertyAccessor     : System.__ComObject

PS 7.0.3中的输出

Method invocation Failed because [System.__ComObject] does not contain a method named 'AddressLists'.

您是否知道为什么在新的Powershell版本中无法使用?

解决方法

我可以复制该问题。这对您有用吗?它给出相等的结果$Outlook.GetNamespace("MAPI").AddressLists | Where {$_.name -eq 'Global Address List'}

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...