Hi team,
I have about 300 security groups that I need to get the members of into a csv/xls.
All the group names contain the words "VPN User".
I need to get membership for all such group, so is there some type of command or power
Technology Tips and News
Hi team,
I have about 300 security groups that I need to get the members of into a csv/xls.
All the group names contain the words "VPN User".
I need to get membership for all such group, so is there some type of command or power
Hi Triyambak,
where there is a will, there is a script:
Get-ADGroup -Filter { name -like "*VPN User*" } | Get-ADGroupMember | Export-Csv "members.csv"
Cheers,
Fred
Try something like this
Get-ADGroup -Filter {Name -like '*VPN User*'} | Get-ADGroupMember | Export-Csv C:\GroupMembers.csvEDIT: Looks like Fred beat me
Script terminated with below error. output file show username with samid but not their respective
group name
Get-ADGroupMember : The size limit for this request was exceeded
At line:1 char:70
$Groups = Get-ADGroup -filter {name -like "*VPN User*"} -properties description,members $myCol = @() ForEach ($Group in $Groups) { $Members = @(Get-ADGroupMember "$Group") If($Members.count eq 0) { $MyObject = New-Object PSObject -Property @{ Group = $Group.name OUPath = $group.DistinguishedName -replace '^.+?,(CN|OU.+),$1' Type = $group.groupcategory ManagedBy = ($Group.ManagedBy -split ",*..=")[1] Members = "This group is empty" UserEnabled = "" } $mycol += $MyObject } Else { ForEach ($Member in $Members) { try { $MyObject = New-Object PSObject -Property @{ Group = $Group.name OUPath = $group.DistinguishedName -replace '^.+?,(CN|OU.+),$1' Type = $group.groupcategory Members = $member.name UserEnabled = (get-aduser $member.name).Enabled } $mycol += $MyObject } catch { $MyObject = New-Object PSObject -Property @{ Group = $Group.name OUPath = $group.DistinguishedName -replace '^.+?,(CN|OU.+),$1' Type = $group.groupcategory Members = $member.name UserEnabled = "" } $mycol += $MyObject } } } } $myCol |select group,OUPath,type,members,userenabled | export-csv membersingroups.csv -Delimiter ";" -Encoding UTF8 -NoTypeInformation
$Groups = Get-ADGroup -filter {name -like "*VPN User*"} -properties description,members $myCol = @() ForEach ($Group in $Groups) { $Members = @(Get-ADGroupMember "$Group") If($Members.count eq 0) { $MyObject = New-Object PSObject -Property @{ Group = $Group.name OUPath = $group.DistinguishedName -replace '^.+?,(CN|OU.+),$1' Type = $group.groupcategory ManagedBy = ($Group.ManagedBy -split ",*..=")[1] Members = "This group is empty" UserEnabled = "" } $mycol += $MyObject } Else { ForEach ($Member in $Members) { try { $MyObject = New-Object PSObject -Property @{ Group = $Group.name OUPath = $group.DistinguishedName -replace '^.+?,(CN|OU.+),$1' Type = $group.groupcategory Members = $member.name UserEnabled = (get-aduser $member.name).Enabled } $mycol += $MyObject } catch { $MyObject = New-Object PSObject -Property @{ Group = $Group.name OUPath = $group.DistinguishedName -replace '^.+?,(CN|OU.+),$1' Type = $group.groupcategory Members = $member.name UserEnabled = "" } $mycol += $MyObject } } } } $myCol |select group,OUPath,type,members,userenabled | export-csv membersingroups.csv -Delimiter ";" -Encoding UTF8 -NoTypeInformation