简体   繁体   English

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

[英]From within Powershell, how do I pass an IEnumerable argument?

I'm trying to use the Microsoft.Lync.Model.Contact.GetContactInformation() method. 我正在尝试使用Microsoft.Lync.Model.Contact.GetContactInformation()方法。 There are two versions, one which takes a plain enum, and another which takes an IEnumerable with multiple values. 有两个版本,一个采用普通枚举,另一个采用具有多个值的IEnumerable。

http://msdn.microsoft.com/en-us/library/lync/hh347568.aspx http://msdn.microsoft.com/en-us/library/lync/hh347568.aspx

I can use the first version semi-successfully (until I try to retrieve one for which there is no value), but I can't make any sense of how I'm supposed to pass in the multiple arguments. 我可以成功使用第一个版本(直到尝试检索没有值的版本),但是我对应该如何传入多个参数毫无意义。

$contactInfo = $c[$c.Count - 1].Participants[1].Contact.GetContactInformation([int[]]("FirstName", "LastName", "DisplayName", "PrimaryEmailAddress"))

(The above doesn't work.) (以上操作无效。)

Can someone nudge me in the right direction? 有人可以向正确的方向推动我吗?

The simplest syntax would be close to what you have now. 最简单的语法将与您现在拥有的语法非常接近。 The method takes an enumeration of ContactInformationType values, so your cast should be to an array of those, not int . 该方法采用ContactInformationType值的枚举,因此您的强制转换应该是一个数组,而不是int

Also, you can use $foobar[-1] as sugar for $foo[$foo.Count - 1] , ie to get the last element. 另外,您可以将$foobar[-1]用作$foo[$foo.Count - 1]糖,即获取最后一个元素。

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

I think it will work if you try something like below: 我认为,如果您尝试以下操作,它将起作用:

$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))

The method itself probably doesn't know what "FirstName" is. 该方法本身可能不知道“ FirstName”是什么。 Try creating an array of the enum-values, like: 尝试创建一个枚举值数组,例如:

$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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM