Powershell: A variable within a variable; Variableception

When defining variables in PowerShell, single quotes (') mean you want the literal version of the string. Use double-quotes (") if you want to allow variable expansion:

PS C:\> $a = "hello"
PS C:\> $a
hello
PS C:\> $b = "$a world!"
PS C:\> $b
hello world!

More info:

  • Single Quotes vs. Double Quotes in PowerShell: What's the Difference?
  • Referencing Variables and Variable Values

Edit after comments:

For your example where you're pulling the line from a file, that's a little trickier since it's pulling the line as a literal string.

The easiest way (IMO) would be to use the Replace method; something like:

$selHost = (get-content c:\scripts\hosts.txt)[0]
$a = ((get-content c:\scripts\config.txt)[1]).replace('$selhost', $selHost)