Link to home
Start Free TrialLog in
Avatar of MilesLogan
MilesLoganFlag for United States of America

asked on

Get AD Group Member details

Hi EE

I have the script below that will pull AD group member information from the groups entered in the txt file . Can someone help me modify it so it prompts me for the group name?


Import-Module Activedirectory
[array]$Members=$null
GC groups.txt | % {
$Group = Get-ADGroup $_  -ErrorAction SilentlyContinue
If ($Group){
$members += Get-ADGroup $Group.Name -Properties Members |
                Select-Object -ExpandProperty Members |
                Get-ADObject -properties Samaccountname |
                ?{$_.ObjectClass -eq "user"}  | Get-aduser -Properties * |
        Select @{L='GroupName';e={$Group.Name}},Name,Samaccountname,mail
 }
}
$Members | Select * | Export-Csv GroupDetails_$((Get-Date -Format MM-dd-yyyy)).csv -NoTypeInformation
ASKER CERTIFIED SOLUTION
Avatar of Aard Vark
Aard Vark
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MilesLogan

ASKER

Thank you Learnctx !!