1
Import-Module activedirectory

[string]$Name = "Larry Page"
Get-ADUser -Filter 'Name -like "$Name"'

How do I get the name into the variable? At execution, it doesn't appear to substitute the name at runtime

3

1 Answer 1

8

You have the quotes flipped. Variable substitution only happens with double quoted strings. The first set of single quotes tells PowerShell to not do the substitution. If you use double quotes on the outside, you can use the singles inside and still get the substitution.

Import-Module activedirectory

[string]$Name = "Larry Page"
Get-ADUser -Filter "Name -like '$Name'"
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.