简体   繁体   中英

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

I'm trying to use the Microsoft.Lync.Model.Contact.GetContactInformation() method. There are two versions, one which takes a plain enum, and another which takes an IEnumerable with multiple values.

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 .

Also, you can use $foobar[-1] as sugar for $foo[$foo.Count - 1] , ie to get the last element.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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