Primoz
Primoz

Reputation: 4331

Why this powershell code returns whole objects insted of just selected properties?

Why this powershell code returns whole objects insted of just selected properties ? I want to get only name and SID for each user not whole Microsoft.ActiveDirectory.Management.ADAccount object with bounch of properties.

PS C:\> Get-ADUser -filter * -SearchBase "OU=mailOnly,DC=test,DC=demo,DC=local" -server test.demo.local -properties SID,Name

Best regards, Primoz.

Upvotes: 1

Views: 751

Answers (2)

Keith Hill
Keith Hill

Reputation: 201682

It appears that the -Property merely retrieves additional properties and tacks them onto the returned object e.g.:

Properties

Specifies the properties of the output object to retrieve from the server. Use this parameter to retrieve properties that are not included in the default set.

You can pick off the properties you want using Select-Object like so:

Get-ADUser -filter * -SearchBase "OU=mailOnly,DC=test,DC=demo,DC=local" `
           -server test.demo.local -properties SID,Name | Select SID,Name

Upvotes: 4

Avilo
Avilo

Reputation: 1204

The -properties option on Get-ADUser retrieves extended active directory properties beyond the base set included on the objects. If instead you want to see the value of those two properties, pass the result set through format-list.

Get-ADUser -filter * -SearchBase "OU=mailOnly,DC=test,DC=demo,DC=local" -server test.demo.local -properties SID,Name
 | format-list -property SID,Name

Upvotes: 0

Related Questions