Active Directory get list of users with PowerShell

Today, I had task how to export list of users from specific group.

So it’s easy:
1. Open PowerShell
2. Run:
Import-Module ActiveDirectory //this will load Active Directory libs
3. Get-ADGroupMember -identity “Enterprise Admins” | select name | Export-csv -path C:\Output\EnterpriseAdmins.csv -NoTypeInformation

With this command you don’t need to specify whole object path, just name, if you have another group name – just replace Enterprise Admins with your group name. Please make sure you have Output directory on drive C, otherwise you will got next:
Export-Csv : Could not find a part of the path 'C:\output\EnterpriseAdmins.csv'.
At line:1 char:74
+ Get-ADGroupMember -identity "Enterprise Admins"| select name | Export-csv <<<< -path c:\output\EnterpriseAdmins.csv -NoTypeInformation
+ CategoryInfo : OpenError: (:) [Export-Csv], DirectoryNotFoundEx ception
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.Ex portCsvCommand

I hope this will help you.

About nicoljako

Cofounder Kresalo., sysadmin, architect of IT infrastructures, DevOps
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment