Using -filter with variables in string

you would do it like below

Get-ADUser -filter "DisplayName -like '*$lastName*$firstName*'"

[quote quote=167221]you would do it like below

Get-ADUser -filter "DisplayName -like '*$lastName*$firstName*'"
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[/quote] Is there a reason you used single quotes instead of double quotes?

E.g.

Get-ADUser -filter "DisplayName -like `"*$lastName*$firstName*`""

I get the same result, but I suppose the single quotes way is cleaner.

unless escaped or using here strings, same type of quotes cannot be used with in them.

The filter isn’t really a script block, but it seems like everybody uses it, even the online help.

Thank you both for the information!