可以将变量的值用作新的变量名吗?

时间:2019-06-06 13:12:14

标签: powershell variables

长时间的听众,第一次的听众! :)所以我觉得这是可能的,只是解决方案使我无所适从。

我正在设置一个变量($thisName = "a"),并使用该变量创建对象。

我希望不仅将$thisName用作属性,还将对象的名称用作

这可能吗?

$thisName = "a"

$theseParams = @{ Name = $thisName; DebugMode = $true }

$thisName = New-Object [PSCustomObject] -Property @theseParams

我想要将对象的变量名设为$a,并将$a.Name设为“ a”。但是我只是重置(或彻底中断)$thisName

1 个答案:

答案 0 :(得分:0)

我相信新变量可能会有所帮助:

$thisName = "a"
$theseParams = @{ Name = $thisName; DebugMode = $true }
New-Variable -Name $thisName -Value $theseParams

输出似乎是您要的:

PS C:\> $a.Name
a
PS C:\> $a

Name                           Value
----                           -----
DebugMode                      True
Name                           a

希望这会有所帮助。

相关问题