This script works for one group. How can i get this to except multiple groups?
Get-ADGroupMember “ADGroup” -Recursive | select name | export-csv C:\Group.txt -NoTypeInformation -Append
$a = Get-Content C:\Group.txt
$a | Foreach-Object {$_ -replace ‘"’, ‘’}| Out-File C:\Group.txt
Get-Content C:\Group.txt | Get-ADUser -Properties * | Select-Object name,Surname,GivenName,emailaddress,distinguishedname | Export-Csv c:\Group.csv -notypeInformation
I don’t have access to my Active Directory environment to test, but something like this should work.
$groups = get-adgroup -Filter * -Properties members
$groups.members | ForEach-Object {
Get-ADUser $_ -Properties * | Select-Object name,
Surname,GivenName,emailaddress,distinguishedname} |
Export-Csv C:\groups.csv -NoTypeInformation
how does
$groups = get-adgroup -Filter * -Properties members
know what groups i want to export users from?
@Windows LiveUser150: Do you already have a textfile or CSV in where you have your groups specified?
yes. its about 10 so i just did it manually.
@Windows LiveUser150:
the code posted by random commandline would be running through all groups.
for your use-case, since you already seem familiar with get content, utilizing a text document listing the groups you want, i would do something along the lines of
$grouplist = get-content c:\groupstocheck.txt
foreach ($group in $grouplist)
{
get-adgroupmember $group|get-aduser -properties mail| Select-Object name,Surname,GivenName,mail,distinguishedname | Export-Csv c:\Group.csv -notypeInformation -append
}
obviously you could also use a CSV as an imput file and do import-csv instead but that changes a few things.
thanks for answering. I think i tried that but will give a shot
That worked David
At first i didnt have the -append and was only getting the last group in the list. I guess i didnt get it when i copied
Thanks