How to get specific properties using Get-AdUser

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 say, only DisplayName should be returned. He returns everything. The problem is that the DistinguishedName is causing truncation problems in my process. How can I get a script only to return certain properties?

+6
source share
2 answers

using select-object for expample:

 Get-ADUser -Filter * -SearchBase 'OU=Users & Computers, DC=aaaaaaa, DC=com' -Properties DisplayName | select -expand displayname | Export-CSV "ADUsers.csv" 
+8
source

This worked for me too:

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"

+4
source

Source: https://habr.com/ru/post/944982/


All Articles