If I have a bunch of variables like so:
$WebServerAlphaDescription = "Some interesting stuff about this webserver" $WebServerBetaDescription = "Some interesting stuff about this webserver" $DatabaseServerDescription = "Some interesting stuff about this database server" $ExchangeServerDescription = "Some Interesting stuff about this exchange server"
...
and I have an array that holds the part of the variable name:
myArray = @("WebServerAlpha","WebServerBeta","DatabaseServer","ExchangeServer")
is it possible for me to construct and expand a variable from the components to do something like this:
$serverDescriptions = @() foreach ($name in $myArray){ $serverDescriptions += $($name)+"Description" }
PS C:\> $serverDescriptions
Some interesting stuff about this webserver
Some interesting stuff about this webserver
Some interesting stuff about this database server
Some Interesting stuff about this exchange server
...
When I tried doing this I just get the variable names as strings like this:
$WebServerAlphaDescription
$WebServerBetaDescription
$DatabaseServerDescription
$ExchangeServerDescription
...
I want powershell to see them as variable names and expand them instead of as strings. Any ideas on how I can accomplish this?
Any assistance is appreciated!