Powershell -like won't compare to variable -


in powershell, can this:

    $useraccount = get-aduser -filter { name -like "*smith*"} 

and find user(s), when this:

    $namefilter = "smith"     $useraccount = get-aduser -filter { name -like "*$namefilter*"} 

nothing found. why?

-filter looks accepts script block where-object, it's string. if use curly braces syntax, tends treat literal string, variables won't expand.

try:

$useraccount = get-aduser -filter "name -like '*$namefilter*'" 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -