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

asked on

Export AD group members into separate files

Can someone help me modify this script so the output is for each group in its own CSV as the group name and date ?



code]Import-Module -Name Activedirectory
[array]$Members=$null
Get-Content C:\Temp\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 Samaccountname,name|
      Select-Object -Property @{L='GroupName'
e={$Group.Name}},Samaccountname,name
 }
}
$Members | Select-Object -Property * |Export-Csv -Path "C:\Temp\GroupName_$((Get-Date -Format MM-dd-yyyy-hh-mm)).csv" -NoTypeInformation[/code]
ASKER CERTIFIED SOLUTION
Avatar of Sam Jacobs
Sam Jacobs
Flag of United States of America 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

Hey Sam !! thank you much 
Miles,

You are most welcome.

-Sam
P.S. Curious to know whether your UniversalDashboard works when you update the version.