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"
Share:
205,785

Related videos on Youtube

kickinchicken
Author by

kickinchicken

Updated on July 20, 2022

Comments

  • kickinchicken
    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
    kickinchicken about 11 years
    hmmm... that returned an error: ArgumnetNull.Microsoft.PowerShell.Commands.SelectObjectComma‌​nd.
  • kickinchicken
    kickinchicken about 11 years
    I'm looking into the syntax for Select-Object though. If it works I'll post the script.
  • CB.
    CB. about 11 years
    the error says that the user in the pipe have not set a displayname.Try removing the -expand
  • kickinchicken
    kickinchicken about 11 years
    Get-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
    kickinchicken about 11 years
    That's what's working for me now. May be a bit long winded but it works! Thanks for your help guys!
  • samus
    samus about 6 years
    select isn't mentioned in the docs... What if there are multiple properties?
  • samus
    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
    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
    TylerH over 3 years
    @samis same thing as above; remove -expand

Related