1

I'm having trouble passing a variable with a wildcard to search AD against displayname filter. If I put someones name followed by a wildcard it works correctly. But not with a variable. Any ideas?

    $data=import-csv C:\myscripts\listofnames.csv
    foreach($user in $data.displayname)
    {
      get-aduser -filter {(displayname -like "$user *")} -Properties displayname
    }

What am I missing? if I don't do a -filter against Displayname and instead pipe a where-object displayname it works fine but takes forever that route.

Refried04
  • 223
  • 2
  • 4
  • 9

1 Answers1

2

I recommend using the -LDAPFilter parameter instead.

Get-ADUser -LDAPFilter "(displayName=$user *)" -Properties displayName
Bill_Stewart
  • 22,916
  • 4
  • 51
  • 62