Getting members from AD

ivan rosa
ivan rosa used Ask the Experts™
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
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
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

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... :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial