Im sure this is just a syntax error, but im trying to search AD users, and I cannot figure out why this does not work:
Write-Host "Enter LastName or UserName:"
$x = Read-Host
Get-ADUser -Filter { SAMAccountName -like '*$x*' } -Properties DispalyName | FT -Properties DisplayName
Just doesnt return anything. And im sure it is syntax with the “*”. but not sure why. Thanks for any help.
$x is not expanded inside the Filter scriptblock, this should do the job:
Alternatively, you could use ldap filter: