代码之家  ›  专栏  ›  技术社区  ›  webnoob

如何将数组作为自定义PSObject的返回类型

  •  0
  • webnoob  · 技术社区  · 7 年前

    我有以下几点:

    # Compare the 2 lists and return the ones that exist in the top and children (meaning they're redundant).
    $redundantUsers = $usersAssignedToThisGroup | where { $usersAssignedToGroupsInThisGroup -contains $_ }
    
    # Build the results to output
    $results += New-Object PSObject -property @{
        group = $group.name #group assigned out of scope
        users = @($redundantUsers)
    }
    

    $users = ./MyScript -myParam "something" | Select users
    

    然后我希望能打字 $users[1] 并获取该数组的第一个元素。

    但是,我不得不这样做 $users[0].users[1]

    我基本上只是想让脚本以一种有用的方式返回数据。

    0 回复  |  直到 7 年前
    推荐文章