Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
每次循环运行时如何创建一个新变量?
类似的东西
for ($i=1; $i -le 5; $i++) { $"var + $i" = $i write-host $"var + $i }
使用New-Variableand Get-Variable(注意可用的选项,包括范围)。例如
New-Variable
Get-Variable
for ($i=1; $i -le 5; $i++) { New-Variable -Name "var$i" -Value $i Get-Variable -Name "var$i" -ValueOnly }