简体   繁体   中英

use a string as variable powershell

$VAR_555_SERVER=C:\HERE
$OTHER="555"
$THIS=('$VAR_'+"$OTHER"+"_SERVER")
$THIS

Now $THIS should be $VAR_555_SERVER and $VAR_555_SERVER is C:\\HERE . Actual result is $VAR_555_SERVER as string, how can I use it as variable?

您可以使用Invoke-Expression

$THIS=Invoke-Expression ('$VAR_'+"$OTHER"+"_SERVER")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM