Forum Discussion

Re: Need help exporting list of enabled group members

Baron164 Piping like that doesn't work (You're not using a Foreach in it), I changed it to something somewhat longer which also displays the group name in the CSV file

 

 

$total = @()
$group = 'Group1'
foreach ($user in Get-ADgroupMember $group -Recursive | Where-Object objectClass -eq user ) {
    if ((Get-ADUser $user.SamAccountName).enabled -eq 'True') {
        $founduser = [PSCustomObject]@{
            Group = $group 
            User  = $user.name
        }
        $total += $founduser
    }
}
$total | Export-Csv -Encoding UTF8 -Path \\domain.local\share\exportmembers.csv -NoTypeInformation -Delimiter ';'

 

14 Replies

  • Baron164's avatar
    Baron164
    Brass Contributor

    So it's only providing me with two user accounts, which is the same that I was getting. My initial line when it's exporting everything returns over 100 users. But when I try to specify only enabled users I only get two listed. The group I'm currently trying to export from has a lot of nested groups within it.

Resources