troubleshooting Question

Powershell list users with filtered groups

Avatar of Triforce2000
Triforce2000Flag for Belgium asked on
2 Comments1 Solution67 ViewsLast Modified:
I want to list all users with filtered AD groups, so I want all groups beginning with BLOG.
I've got a CSV with the name of all users.

I've tryed this code:
$users = Import-Csv 'C:\temp\old farm\users.csv' -Delimiter ";"

$Report = @()

foreach ($user in $users){
    $name  = $

    $gebruiker = get-aduser -Filter {(displayname -like $name) -AND (enabled -eq $true)} -Properties *
    $sam = $gebruiker.SamAccountName
    $usergroupcollection = Get-ADPrincipalGroupMembership $sam | ? {$ -like "blog*"}
    $usergroupmembership = @()

    foreach ($UserGroup in $usergroupcollection) {
        $GroupDetails = Get-ADGroup -Identity $UserGroup
        $usergroupmembership += $GroupDetails.Name

    $groups = $usergroupmembership -join ','

    $out = New-Object PSObject
    $out | Add-Member -MemberType NoteProperty -Name Name -Value $gebruiker.Name
    $out | Add-Member -MemberType NoteProperty -Name Sam -Value $gebruiker.SamAccountName
    $out | Add-Member -MemberType NoteProperty -Name Groups -Value $groups

    $report += $out

$Report | Sort-Object Name | FT -AutoSize

Open in new window

But there is an error on this
Has anyone a solution for this please?
Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros