variables - Powershell在echo中合并变量

标签 variables powershell

我的脚本有问题。

我想从2个变量创建一个变量,然后回显结果

$a = "server1"
$server_server1 = "Success"

echo ("`$server_$a") 

回声的结果应为成功

提前Thx

最佳答案

您可以使用Get-Variable Cmdlet:
(get-variable "server_$a").Value
从您的示例中可以得到Success

有关Get-Variable的更多信息,请参阅TechNet。

关于variables - Powershell在echo中合并变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22682138/

相关文章:

java - 这是重复局部变量问题的优雅解决方案吗?

Java 错误 - 找不到符号 - 变量是

amazon-web-services - 使用 PowerShell Core 上传到 Amazon S3 存储桶

linux - 如何添加用户以供本地 Powershell 使用? ( Jenkins 和本地主机用户模拟?)

powershell - 如何在 PowerShell 中对枚举执行按位或 (|)?

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

php - 如何将 php session 变量从页面传输到页面内的 iframe

javascript - 有没有办法防止未定义的javascript变量在插入html时显示 'undefined'?

powershell - "%"(百分比)在 PowerShell 中起什么作用?

powershell - Powershell-将多个Get-Date命令添加到变量中