在PowerShell中返回多值字段中的特定值

时间:2015-10-26 04:56:43

标签: powershell

我试图弄清楚如何只返回PowerShell中多值字段中的第一个或第二个值。

例如:

get-aduser -filter * -properties * | select proxyaddresses

这将返回所有用户的所有proxyaddreses - 但我只想要字段中的第一个或第二个值。我怎么能这样做?

1 个答案:

答案 0 :(得分:2)

更新以包含Ryan的评论。

您可以使用Select-Object模块的第一个选项(select是别名)。

# This will get the first 2 elements from whatever you pipe into the module
$x | Select-Object -first 2

对于您的查询,您只需将该选项添加到现有的select子句

即可
get-aduser -filter * -properties * | select proxyaddresses -first 2

其他选项包括获取最后的x个元素,跳过前x个元素等。 https://technet.microsoft.com/en-us/library/hh849895.aspx