How do I get specific properties with Get-AdUser
205,785
Solution 1
using select-object
for example:
Get-ADUser -Filter * -SearchBase 'OU=Users & Computers, DC=aaaaaaa, DC=com' -Properties DisplayName | select -expand displayname | Export-CSV "ADUsers.csv"
Solution 2
This worked for me as well:
Get-ADUser -Filter * -SearchBase "ou=OU,dc=Domain,dc=com" -Properties Enabled, CanonicalName, Displayname, Givenname, Surname, EmployeeNumber, EmailAddress, Department, StreetAddress, Title | select Enabled, CanonicalName, Displayname, GivenName, Surname, EmployeeNumber, EmailAddress, Department, Title | Export-CSV "C:\output.csv"
Related videos on Youtube
Author by
kickinchicken
Updated on July 20, 2022Comments
-
kickinchicken almost 2 years
I have the following PS script written:
Get-ADUser -Filter * -SearchBase 'OU=Users & Computers, DC=aaaaaaa, DC=com' -Properties DisplayName | Export-CSV "ADUsers.csv"
From what I can tell it should be returning only DisplayName. It's returning everything though. Problem is that DistinguishedName is causing truncation problems later on in my process. How can I get the script to only return certain properties?
-
kickinchicken about 11 yearshmmm... that returned an error: ArgumnetNull.Microsoft.PowerShell.Commands.SelectObjectCommand.
-
kickinchicken about 11 yearsI'm looking into the syntax for Select-Object though. If it works I'll post the script.
-
CB. about 11 yearsthe error says that the user in the pipe have not set a displayname.Try removing the
-expand
-
kickinchicken about 11 yearsGet-ADUser -Filter * -SearchBase 'OU=Users & Computers, DC=aaaaa, DC=com' -Properties EmployeeNumber,GivenName, Surname, EmailAddress, OfficePhone, PostalCode, City, StreetAddress, Office,Company, Title, SID | select EmployeeNumber,GivenName, Surname, EmailAddress, OfficePhone, PostalCode, City, StreetAddress, Office,Company, Title,SID | Export-CSV "../SSIS/Import Data/ADUsers.csv"
-
kickinchicken about 11 yearsThat's what's working for me now. May be a bit long winded but it works! Thanks for your help guys!
-
samus about 6 years
select
isn't mentioned in the docs... What if there are multiple properties? -
samus about 6 years
get-aduser user1 -properties PasswordExpired, PasswordLastSet | select -expand PasswordExpired, PasswordLastSet
Select-Object : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'ExpandProperty'. Specified method is not supported. -
samus about 6 years
get-aduser user1 -properties PasswordExpired, PasswordLastSet | select -expand PasswordExpired -expand PasswordLastSet
: Select-Object : Cannot bind parameter because parameter 'ExpandProperty' is specified more than once. To provide multiple values to parameters that can accept multiple values, use the array syntax. For example, "-parameter value1,value2,value3". -
TylerH over 3 years@samis same thing as above; remove
-expand