Powershell: use variable with wildcard with get-aduser

powershell

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

Best Answer

$lastname = "smith"
Get-ADUser -LDAPFilter "(&(objectCategory=person)(objectClass=user)(Sn=*$lastname*))"

Returns a list of users whose last name (surname) matches the search pattern of *smith*, so it will return Haysmith, Smithwood, McSmithers, etc.