在Powershell中,如何传递IEnumerable参数?

在Powershell中,如何传递IEnumerable参数?,powershell,lync,Powershell,Lync,我正在尝试使用Microsoft.Lync.Model.Contact.GetContactInformation()方法。有两个版本,一个采用普通枚举,另一个采用具有多个值的IEnumerable 我可以半成功地使用第一个版本(直到我尝试检索一个没有值的版本),但我无法理解如何传入多个参数 $contactInfo = $c[$c.Count - 1].Participants[1].Contact.GetContactInformation([int[]]("FirstName", "La

我正在尝试使用Microsoft.Lync.Model.Contact.GetContactInformation()方法。有两个版本,一个采用普通枚举,另一个采用具有多个值的IEnumerable

我可以半成功地使用第一个版本(直到我尝试检索一个没有值的版本),但我无法理解如何传入多个参数

$contactInfo = $c[$c.Count - 1].Participants[1].Contact.GetContactInformation([int[]]("FirstName", "LastName", "DisplayName", "PrimaryEmailAddress"))
(上述方法不起作用。)


有人能把我推到正确的方向吗?

我想如果你尝试以下方法,它会起作用:

$contactInfo = $c[$c.Count - 1].Participants[1].Contact.GetContactInformation(
                [int[]](
                        [int]Microsoft.Lync.Model::ContactInformationType.FirstName,
                        [int]Microsoft.Lync.Model::ContactInformationType.LastName,
                        [int]Microsoft.Lync.Model::ContactInformationType.DisplayName,
                        [int]Microsoft.Lync.Model::ContactInformationType.PrimaryEmailAddress))

该方法本身可能不知道“FirstName”是什么。尝试创建枚举值数组,如:

$information = [Microsoft.Lync.Model.ContactInformationType]::FirstName, [Microsoft.Lync.Model.ContactInformationType]::LastName, [Microsoft.Lync.Model.ContactInformationType]::DisplayName, [Microsoft.Lync.Model.ContactInformationType]::PrimaryEmailAddress
$contactInfo = $c[$c.Count - 1].Participants[1].Contact.GetContactInformation($information)

最简单的语法与您现在的语法非常接近。该方法采用
ContactInformationType
值的枚举,因此您的强制转换应该是这些值的数组,而不是
int

此外,您还可以使用
$foobar[-1]
作为
$foo[$foo.Count-1]
的糖,即获取最后一个元素

$contactInfo = $c[-1].Participants[1].Contact.GetContactInformation([Microsoft.Lync.Model.ContactInformationType[]] @("FirstName", "LastName", "DisplayName", "PrimaryEmailAddress"))

为什么要将字符串数组转换为int数组?我怎么知道呢,我宁愿编写bash脚本。事实上,我更希望微软编写的软件具有适度的可扩展性,这样我就不必为了得到一个咆哮的通知而涉入这堆废话。