I'd like to do something like this, mainly for code readability:
$ADProperties = "extensionAttribute1,Department,Company,telephoneNumber"
$ADFilter = "{(objectClass -eq "user") -and (enabled -eq $True)}"
Get-ADUser -Filter $ADFilter -Properties $ADProperties
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
:
$ADProperties = "EmployeeID","EmployeeNumber","extensionAttribute1","Department"
(Thanks Eris) but this throws error:
$ADProperties = extensionAttribute1,Department,Company,telephoneNumber
Also, per Vasili, this works:
$str = @("foo","bar")
This works for -Filter
$ADFilter = {(objectClass -eq "user") -and (enabled -eq $True)}
Thanks everyone. MOB
The Properties parameter takes a string[]
(array) data type, as such, it is expecting something more like this:
@("extensionAttribute1","Department","Company","telephoneNumber")
You can do it if you construct your command in a String Variable like this:
$cmd = Get-ADUser -Filter $ADFilter -Properties $ADProperties
And then invoke it
invoke-command $cmd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With