AugieDawg
AugieDawg

Reputation: 43

Return specific value in multivalued field in PowerShell

I'm trying to figure out how to return only the first, or second value in a multivalued field in PowerShell.

For example:

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

This will return all the proxyaddreses for all users - but I just want the first or second value in the field. How can I do that?

Upvotes: 0

Views: 1661

Answers (1)

Alec  Collier
Alec Collier

Reputation: 1523

Updated to include Ryan's comment below.

You can use the first option of the Select-Object module (select is an alias).

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

For you query, you can just add the option to your existing select clause

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

Other options include getting the last x elements, skipping the first x elements, etc. https://technet.microsoft.com/en-us/library/hh849895.aspx

Upvotes: 2

Related Questions