Variables 作为变量名称一部分的变量值

Variables 作为变量名称一部分的变量值,variables,powershell,Variables,Powershell,我对Powershell还是有点陌生,我想知道是否可以使用变量的值作为变量名的一部分 $a = "Stuff"; $abc???_def; # ??? = It's where I want to use $a 看起来这样做的方法是使用新变量语法 以你为例,你会这样做 New-Variable "abc&a_def" "value" 有关详细信息,请参阅 费西蒙纳齐对这个问题的回答值得高度赞扬: 您可以使用新变量执行此操作: $a = "Stuff" New-Variable -N

我对Powershell还是有点陌生,我想知道是否可以使用变量的值作为变量名的一部分

$a = "Stuff";
$abc???_def;  # ??? = It's where I want to use $a

看起来这样做的方法是使用
新变量
语法

以你为例,你会这样做

New-Variable "abc&a_def" "value"
有关详细信息,请参阅

费西蒙纳齐对这个问题的回答值得高度赞扬:

您可以使用新变量执行此操作:

$a = "Stuff"
New-Variable -Name "abc$($a)_def" -Value 'This is abcStuff_def'
Get-Variable abc*


Name                           Value                                                                 
----                           -----                                                                 
abcStuff_def                   This is abcStuff_def                                                  
但我怀疑哈希表可能是更好的选择:

$abc = @{}
$a='Stuff'
$abc.$a = 'This is abcStuff_def'
$abc


Name                           Value                                                                 
----                           -----                                                                 
Stuff                          This is abcStuff_def