【问题标题】:From within Powershell, how do I pass an IEnumerable argument?在 Powershell 中,如何传递 IEnumerable 参数?
【发布时间】:2013-03-06 19:00:26
【问题描述】:

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

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

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

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

(以上行不通。)

有人可以将我推向正确的方向吗?

【问题讨论】:

  • 为什么要将字符串数组转换为 int 数组?
  • 我怎么知道,我宁愿写一个 bash 脚本。实际上,我宁愿微软编写可适度扩展的软件,这样我就不必为了得到 Growl 通知而陷入这种废话。

标签: powershell lync


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    我认为如果您尝试以下方法,它会起作用:

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

    【讨论】:

      【解决方案3】:

      该方法本身可能不知道“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)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2010-12-18
        • 1970-01-01
        • 2012-12-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-10-28
        • 1970-01-01
        相关资源
        最近更新 更多