Can I pass Powershell Get-ADUser -Properties in a variable?

Question:

I’d like to do something like this, mainly for code readability:

I get errors like: Get-Aduser : One or more properties are invalid.

Seems like I’ve seen a way to pass either the Filter or Properties somehow, but can’t find it now.

EDIT – This works for -Properties:

(Thanks Eris) but this throws error:

Also, per Vasili, this works:

This works for -Filter

Thanks everyone.
MOB

Answer:

The Properties parameter takes a string[] (array) data type, as such, it is expecting something more like this:

@("extensionAttribute1","Department","Company","telephoneNumber")

Source:

Can I pass Powershell Get-ADUser -Properties in a variable? by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply