Reputation: 1565
In Powershell, I can do this:
$Useraccount = Get-ADUser -Filter { Name -like "*Smith*"}
and find some user(s), but when I do this:
$namefilter = "Smith"
$Useraccount = Get-ADUser -Filter { Name -like "*$namefilter*"}
nothing is found. Why?
Upvotes: 0
Views: 879
Reputation: 32170
-Filter
looks like it accepts a script block like Where-Object, but it's actually a string. If you use the curly braces syntax, it tends to treat it like a literal string, so variables won't expand.
Try:
$Useraccount = Get-ADUser -Filter "Name -like '*$namefilter*'"
Upvotes: 3