MilesLogan
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}},Samaccoun tname,name
}
}
$Members | Select-Object -Property * |Export-Csv -Path "C:\Temp\GroupName_$((Get- Date -Format MM-dd-yyyy-hh-mm)).csv" -NoTypeInformation[/code]
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}},Samaccoun
}
}
$Members | Select-Object -Property * |Export-Csv -Path "C:\Temp\GroupName_$((Get-
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Miles,
You are most welcome.
-Sam
P.S. Curious to know whether your UniversalDashboard works when you update the version.
You are most welcome.
-Sam
P.S. Curious to know whether your UniversalDashboard works when you update the version.
ASKER