0

This line works.

get-aduser -f {name -like '*John*'} | format-Table name,SamAccountName

===

The following doesn't work. Your help will be greatly appreciated, thank you very much in advance.

$name = Read-Host "Enter a First Name or Last Name"  
$uname = "'*" + $name + "*'"   
get-aduser -f {name -like $uname } | Format-Table name, SamAccountName

===

Orlando
  • 11
  • 2

2 Answers2

1

Your extra single quotes are not needed and getting included in the search so you end up searching for '*John*' instead of *John*, so the name should not start and end with '

Just change to

$uname = "*$name*"
mklement0
  • 382,024
  • 64
  • 607
  • 775
ViperTG
  • 76
  • 2
0

Remove the ' at the end and the start of line 2, like this:

$name = Read-Host "Enter a First Name or Last Name"  
$uname = "*" + $name + "*"   
get-aduser -f {name -like $uname } | Format-Table name, SamAccountName
Fabian Mendez
  • 512
  • 5
  • 15