Powershell 向具有非常规名称的字符串数组中添加项
我试图以另一个变量的值命名一个数组,然后通过引用该变量的值向其添加多个项 例如,我可以执行以下操作:Powershell 向具有非常规名称的字符串数组中添加项,powershell,Powershell,我试图以另一个变量的值命名一个数组,然后通过引用该变量的值向其添加多个项 例如,我可以执行以下操作: PS C:\Users\Administrator> $IP_Address = "100.100.100.5" PS C:\Users\Administrator> New-Variable -Name $IP_Address PS C:\Users\Administrator> Set-Variable -Name $IP_Address -Value "Test stri
PS C:\Users\Administrator> $IP_Address = "100.100.100.5"
PS C:\Users\Administrator> New-Variable -Name $IP_Address
PS C:\Users\Administrator> Set-Variable -Name $IP_Address -Value "Test string"
PS C:\Users\Administrator> Get-Variable -Name 100.100.100.5
Name Value
---- -----
100.100.100.5 Test string
PS C:\Users\Administrator> ${100.100.100.5}
Test string
但是我无法通过使用
$IP\u Address
引用变量${100.100.100.5}
来了解如何将项添加到变量${100.100.5}
中。您不能使用变量来命名${variableName}
语法中的另一个变量。这就是为什么我们有Get Variable
Get-Variable -Name $IP_Address -ValueOnly
你想达到什么目的?