Hi,
Like this
Users name: - Group description
Joe Dalton
G:\Informatique\page\oui
H:\IT\STI\CessAllo
Joe Willis
P:\Projet\ici\tourne
H:\IT\STI\CessAllo
Thanks!
Hi,
Like this
Users name: - Group description
Joe Dalton
G:\Informatique\page\oui
H:\IT\STI\CessAllo
Joe Willis
P:\Projet\ici\tourne
H:\IT\STI\CessAllo
Thanks!
Hello @Wilfried-THIAM ,
Not sure if this is what you are looking for...
Get-ADPrincipalGroupMembership <username> | Get-ADGroup -Properties * | select name, description
This will return a list of groups a user belongs to and the description for the group, if there is one.
If you are looking for something else, let me know.
Mike
Mike Rodrick
Edutainer, ITProTV
**if the post above has answered the question, please mark the topic as solved.
Wilfred,
Mike gave you a great suggestion already, I thought I would add another option for you depending on how complex you may want to be. Copy everything Between the ======== lines and paste into Powershell ISE to ensure that the script sets up correctly. Also, you will have to modify the searchbase values and potentially the output path for the report in the last line. You may also not want the properties declared in the script (DisplayName and EmployeeID) and may want to change them out for other properties.
Hope that gives you another option that may work.... Good Luck !!!
=========================================================================================================================
Import-Module Activedirectory
Get-ADUser -Filter * -Properties DisplayName,EmployeeID,memberof - searchbase 'OU=Users,OU=CONTAINER,DC=DOMAIN,DC=local' | % {
New-Object PSObject -Property @{
UserName = $_.DisplayName
EmployeeID = $_.EmployeeID
Groups = ($_.memberof | Get-ADGroup | Select -ExpandProperty Name) -join ","
}
} | Select UserName,EmployeeID,Groups | Export-Csv C:\Reports\myreport.csv -NTI
==================================================================================================================
Cheers,
Adam
Hi Mike,
thanks for your answer.Yeah it's almost what I want.I would like to have it for "ALLUsers" in my domain.
I have try to do this with * but it does work:
Get-ADPrincipalGroupMembership * | Get-ADGroup -Properties * | select name, description
thanks!
@adam-gordon said in Powerhsll - how can i list both username and group membership for users of a description group?:
Get-ADGroup | Select -ExpandProperty Name
Hi Adam,
Thanks I have made the the test but I having issue with the script.I have an error on : UserName = $.DisplayName line.
And also for the " Select -ExandProperty " I would like to have only the "description" of the group not the name.
Thank you!
Wilfred,
I am sure we can sort it out. Can you please end me the following so I can see what you are doing and what the error(s) you are getting are:
I need you to send me back the script EXACTLY as you are using it
I need to be able to see the error(s) you get when attempting to run the script. Can you either screen capture them, and / or copy them and send them as well.
I'll take a look and then we''ll figure out what to do from there.
Thanks,
Adam
Hi Adam,
Here is the print screen error and the way I'm executing the script.
Thanks for your help!
Wilfred,
I am not sure what happened between me writing the script, copying it, and sending it to you, but it looks like there was a typo on my side that I think is the reason that you are getting the error.
Try this:
Import-Module Activedirectory
Get-ADUser -Filter * -Properties DisplayName,EmployeeID,memberof -searchbase 'OU=Users,OU=CONTAINER,DC=DOMAIN,DC=local' | % {
New-Object PSObject -Property @{
UserName = $_.DisplayName
EmployeeID = $_.EmployeeID
Groups = ($_.memberof | Get-ADGroup | Select -ExpandProperty Name) -join ","
}
} | Select UserName,EmployeeID,Groups | Export-Csv C:\Reports\ADreport.csv -NTI
I believe the typo / issue was the fact that I left out the _ BETWEEN the $ and the .DisplayName, same for EmployeeID on following line.
See if that fixes the issue. also, NO SPACES between the DisplayName,EmployeeID,memberof
Wilfred,
It looks like the _ is being removed by the editor when I hit the SUBMIT button to reply to you. That seems to be the issue, as it just removed it again in the message I sent above this one.
E-mail me directly adam@itpro.tv I will be able to send you the script file directly, which will avoid any additional issues based on the editor modifying the script.
@Wilfried-THIAM and @Adam-Gordon,
the limitation of our replies is that it doesn't know how to handle certain characters it sees as code. I've made a code block out of Adam's previous code that should help if you scroll back up in the thread.
Hopefully, this will make it "usable" and correct.
Cordially,
Ronnie Wong
Edutainer Manager, ACI Learning [ITPRO]
*if the post has answered the question, mark as solved.
**All "answers" and responses are offered "as is" and my opinion. There is no implied service, support, or guarantee by ITProTV.
Hi Adam!
Yes It work know with as soon as I had _ as suggested.! Another question...Is it possible to only get Description information as in this print screen?
Thanks!
Wilfried,
My apologies for not seeing this last part of your question sooner. I am glad that everything else with the script worked well. To get any property that is declared and available to output is a relatively straightforward process.
You would have to find out what the SPECIFIC REFERENCEABLE NAME of the property is, and then call it via the script.
So, in the script we discussed originally:
Import-Module Activedirectory Get-ADUser -Filter * -Properties DisplayName,EmployeeID,memberof -searchbase 'OU=Users,OU=CONTAINER,DC=DOMAIN,DC=local' | % { New-Object PSObject -Property @{ UserName = $_.DisplayName EmployeeID = $_.EmployeeID Groups = ($_.memberof | Get-ADGroup | Select -ExpandProperty Name) -join "," } } | Select UserName,EmployeeID,Groups | Export-Csv C:\Reports\ADreport.csv -NTI
You would modify the line Get-ADUser -Filter * -Properties DisplayName,EmployeeID,memberof
so that the -Properties value(s) produce the output that you want.
The full list of all declared properties for get-aduser can be found here:
Please let me know if you have any other questions.
Cheers,
Adam