Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How can I construct a variable from concatenated text?

$
0
0


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!


Viewing all articles
Browse latest Browse all 21975

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>