powershell: use variable with wildcard with get-aduser

Posted by user179037 on Server Fault See other posts from Server Fault or by user179037
Published on 2013-06-24T20:59:32Z Indexed on 2013/06/24 22:23 UTC
Read the original article Hit count: 2753

Filed under:

powershell newbie here. I am building a simple bit of code to help me find user's by entering letters of user names. How do I get a wildcard to work w/ a variable? this works:

$name=read-host -prompt "enter user's first or last initial"
$userInput=get-aduser -f {givenname -like 'A*' } 
cmd /c echo "output: $userInput"

this does not:

$name=read-host -prompt "enter user's first or last initial"
$userInput=get-aduser -f {givenname -like '$name*' } 
cmd /c echo "output: $userInput"

The first bit of code delivers a list of users with "A" in their name. Any suggestions woudl be appreciated. thanks

© Server Fault or respective owner

Related posts about powershell