Getting members from AD

Hello Folks,

I'm trying to get all users from an active directory GroupMember, I have the following script

get-adgroupmember "TEX_Users" -recursive | % {
    get-aduser $_ -Properties Employeeid | select Name | Out-File -FilePath C:\Window.000\users.txt

Open in new window

When deploying script within the PS console i get the users from that group, although for some with a long name i get something like
john doe smit ...

when I try to export it to a file or CSV, it only shows me one user ...

can anybody suggest me what the error might be or if they have a better script that would also work out...

thanks for looking
ivan rosaAsked:
Who is Participating?
Because you're overwriting the file in each loop iteration.
Try it like this:
Get-ADGroupMember "TEX_Users" -Recursive | ForEach-Object {
	Get-ADUser $_ -Properties EmployeeId | Select-Object Name, EmployeeId
} | Export-Csv -NoTypeInformation -Path -FilePath C:\Window.000\users.csv

Open in new window

ivan rosaAuthor Commented:
Brilliant @oBdA , you're the man as usual!

Just a tiny modification though, export-csv wouldn't take -FilePath , it takes -Path,
I happen do this a lot too... :)
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.

All Courses

From novice to tech pro — start learning today.