0

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.

1 Answer 1

1

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

Get-AdUser -filter "Name -like '*$user*'"
Sign up to request clarification or add additional context in comments.

2 Comments

Lol, I did not know that you could open with double quote and close with single quote. Thats works....
See the about_Quoting_Rules topic technet.microsoft.com/en-us/library/hh847740.aspx for more information.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.