AD User DN info

Below script is working fine. it is exporting DN details of  Groups. I need the output should be username, memberoffgroup & ADuserDN information. thanks in advance

Import-Module ActiveDirectory

$CurrentDate = Get-Date
$CurrentDate = $CurrentDate.ToString('MM-dd-yyyy_hh-mm-ss')
Get-Content "C:\input.txt" | ForEach-Object {
	$SamAccountName = $_
	Get-ADPrincipalGroupMembership -Identity $SamAccountName | Select-Object -Property @{n='SamAccountName'; e={$SamAccountName}} ,Name, DistinguishedName 
} | Export-Csv -NoTypeInformation C:\output_$CurrentDate.csv

Open in new window

LVL 3
SAM ITAD windows Admin Asked:
Who is Participating?
 
Daryl BamforthTechnical ExpertCommented:
Just wanting to clarify exactly what your after here.

For a given user you want their Username, Groups they are a member of, and the Distinguished name for the group they are a member of?

If that's the case your script already returns that ....

If you want to return the Username, Groups they are a member of and the Users distinguished name you can do

get-aduser $samaccountname -properties memberof | Select samaccountname, distinguishedname, memberof

Open in new window

0
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.