Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Thursday, October 17, 2013 11:29 AM
Hi,
would like to know if its possible to use PowerShell to export a list of all users in AD and which Group they are member of as CSV file?
Thanks!
All replies (6)
Friday, October 18, 2013 8:37 AM âś…Answered
Hi,
pls give it a try.
Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description, @{n='MemberOf'; e= { $_.memberof | Out-String}} ,LastLogonDate,Manager,Title,Department,whenCreated,Enabled,Organization | Sort-Object -Property Name | export-CSV c:\ps\aduser.csv
To export with group names only ( ";" delimited)
Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description,@{n='MemberOf'; e= { ( $_.memberof | % { (Get-ADObject $_).Name }) -join ";" }},LastLogonDate,Manager,Title,Department,whenCreated,Enabled,Organization | Sort-Object -Property Name | export-CSV c:\ps\aduser.csv
rgds,
AZ
Thursday, October 17, 2013 11:49 AM
Here is it :
MCITP - Exchange 2010 | MCITP - Windows Server 2008 R2
Friday, October 18, 2013 7:51 AM
Hi Tarique thanks for Your respons.Tried the command but didnt work for me.
Found another command that worked,but the memberof Field status is only :
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
Script i used is:
Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description,memberof,LastLogonDate,Manager,Title,Department,whenCreated,Enabled,Organization | Sort-Object -Property Name | export-CSV c:\ps\aduser.csv
When i Use get-aduser -Identity username -Properties memberof then it Works.
Any idea why?
thanks.
Friday, October 18, 2013 10:27 AM
Hi AZ,
thanks for Your command,the first one Works like a charm.
Now i need to find a way to sort out memberof,since each Group is seperated With ; sign only.So if i filter in Excel i cant get info of how many users are member of that Group.
If you got a tip for that aswell i would be much appreciated!
Friday, October 18, 2013 10:39 AM
Hi Tarique thanks for Your respons.Tried the command but didnt work for me.
Found another command that worked,but the memberof Field status is only :
Microsoft.ActiveDirectory.Management.ADPropertyValueCollection
Script i used is:
Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description,memberof,LastLogonDate,Manager,Title,Department,whenCreated,Enabled,Organization | Sort-Object -Property Name | export-CSV c:\ps\aduser.csv
When i Use get-aduser -Identity username -Properties memberof then it Works.
Any idea why?
thanks.
That's interesting ......
The script in thread , which I have shared with you is working without any issue according to Poster requirement , but here your requirement is differ little bit .. so you need to understand how script is working there ..
However , your original question was " How to Export AD user with member of group only " and that thread is similar to your requirement Except one diffrence : AD user is listed in a CSV file ..
So I would suggest you : ALWAYS PUT QUESTION IN FORUMS WITH COMPLETE DESCRIPTION , WITH YOUR SAMPLE OF CODE WHICH YOU ARE TRYING TO RUN , WITH ERROR AND WITH EXAPLE ..
We can't guess your mind always .... You have to specify clearly ..
Now ,come to the point :
Memberof field will show Microsoft.ActiveDirectory.Management.ADPropertyValueCollection while you export to csv file becouse it is a collection .
Memberof field will show correct in console screen but it faile while exporting to CSV file.
so ,You need to expand this collection into single item ,
Now give a try to below script
Get-ADUser -Filter * -Properties * | Select-Object -Property Name,SamAccountName,Description,@{l='MemberOf'; e= { ( $_.memberof | % { (Get-ADObject $_).Name }) -join ";" }},LastLogonDate,Manager,Title,Department,whenCreated,Enabled,Organization | Sort-Object -Property Name |export-csv c:\ps\aduser.csv -NoTypeInformation
Note : Do note run directly this script on console after copy , first copy to notepad and then run
You can try AZ's suggestion too , that script will also work ..
MCITP - Exchange 2010 | MCITP - Windows Server 2008 R2
Wednesday, October 7, 2015 10:45 AM
Hi
I Use your Scrip
Get-ADUser -Filter * -SearchBase "OU=..." -Properties * | Select-Object -Property Name,LastLogonDate,mail,@{n='MemberOf'; e= { ( $_.memberof | % { (Get-ADObject $_).Name }) -join ";" }},Enabled | Sort-Object -Property Name | FT -Property Name, LastLogonDate, mail, memberOf, Enabled -A | Out-File -width 4096 C:\User\User_$(get-date -Format 'yyyy-MM-dd')_GroupA.txt
But it not returning MemberOf for some users. Apparently this happens only when managers.