0

I am trying to name an array after the value from another variable, and then add multiple items to it by referring to it with the value from mentioned variable.

For example, I can do the following:

PS C:\Users\Administrator> $IP_Address = "100.100.100.5"
PS C:\Users\Administrator> New-Variable -Name $IP_Address
PS C:\Users\Administrator> Set-Variable -Name $IP_Address -Value "Test string"
PS C:\Users\Administrator> Get-Variable -Name 100.100.100.5

Name                           Value
----                           -----
100.100.100.5                  Test string


PS C:\Users\Administrator> ${100.100.100.5}
Test string

But I cannot figure out how to add items into the variable ${100.100.100.5} by refering to it using $IP_Address.

1
  • What is it you're trying to accomplish? Commented Dec 12, 2013 at 1:03

1 Answer 1

1

You can't use a variable to name another variable within the ${variableName} or $variableName syntax. This is why we have Get-Variable e.g.

Get-Variable -Name $IP_Address -ValueOnly
Sign up to request clarification or add additional context in comments.

Comments

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.