Reputation: 61
I want use filter as variable but throws an error can someone help on this
$myvar="test"
Get-ADUser -Filter {name -like "$myvar"} -Properties name |select name
Upvotes: 6
Views: 74253
Reputation: 1
###Dynamic Approach to Lookup a User###
#Get Input to Define Variables
$NameLast = Read-Host 'User Last Name'
$NameFirst = Read-Host 'User First Name'
$NameLookup = "*$NameFirst* *$NameLast*"
#Get-ADuser Lookup Based on Defined Variables
Get-ADuser -Filter {name -like $NameLookup} -Properties * | Select-Object name, samaccountname, emailaddress | Sort-Object samaccountname
Upvotes: -1
Reputation: 37720
Try this:
$myVar = '*test*'
Get-ADUser -Filter {name -like $mvVar} -Properties name | Select-Object Name
Pretty sure Name is a default property by the way.
Upvotes: 8