Aaron Ooi
Aaron Ooi

Reputation: 139

Powershell parameter to variables into a command

I tried to find a way to join or use variable into a command. I'm trying to create a command that accept parameters: The command: aduser.ps1 John

aduser.ps1 script:
Param($User)
Get-AdUser -filter 'Name -like "*$user*"'

I had error and not sure what operator to use to join in the $user variables, i tried + or & and not working for me.

Upvotes: 0

Views: 145

Answers (1)

Shay Levy
Shay Levy

Reputation: 126752

Variables will not expand inside single quote strings, replace them with double quotes:

Get-AdUser -filter "Name -like '*$user*'"

Upvotes: 1

Related Questions