Get AD properties of OU users with Powershell

Hi I have the below script to get users in an OU, is there a handy way to add properties for web page, mobile number etc just for that OU

Get-ADUser -Filter * -SearchBase "OU=test,OU=test1,DC=contoso,DC=local"  -SearchScope OneLevel | export-csv C:\test.csv -NoTypeInformation
LVL 1
Indie101Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
Just add the additional properties (specifying the ldap displayname of the attribute) you want via the -properties parameter of Get-ADUser.
Get-ADUser -Filter * -SearchBase "OU=test,OU=test1,DC=contoso,DC=local"  -SearchScope OneLevel -Properties mobile,mail | export-csv C:\test.csv -NoTypeInformation

Open in new window

0
Indie101Author Commented:
Thanks that didnt work though I dont see the mobile numbers in the csv
0
footechCommented:
Do all the users have a something entered for that attribute?
If not, then it's just PowerShell trying to be too smart, and not creating a column for it because the first result didn't have the property.  You can get around it by specifying all the properties you want to be in the file with a Select-Object command.
Get-ADUser -Filter * -SearchBase "OU=test,OU=test1,DC=contoso,DC=local"  -SearchScope OneLevel -Properties mobile,mail |
 Select "DistinguishedName","Enabled","GivenName","Name","SamAccountName","SID","Surname","UserPrincipalName","mobile","mail" |
 export-csv C:\test.csv -NoTypeInformation

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.