I need loop through all the variables. But it doesn't work.
$var0='a'
$var1='b'
$var2='c'
$i=0; While ($i -lt 3) {
$var[$i]
$i++}
$var=('a','b','c')
$i=0; While ($i -lt 3) {
$var[$i]
$i++}
and it works.
But I need loop variables, was shown in the first block

variable:with a filter for the names you choose ...(get-variable "var$i”).Value, although as others have said, looping through variables is often an indicator that there’s a better data structure to be using, like an array / hashtable…Get-ChildItem -Path variable: | Where-Object -Property Name -Like -Value var*... 🤷🏼♂️ ... but again ... what is it what you're actually trying to do? You're probably doing something wrong ... or at least way more cumbersome than necessary.$variables = @{ var0 = 'a'; var1 = 'b'; ... }then$variables.GetEnumerator() | % { $varname = $_.Key; $varvalue = $_.Value ... }Get-VariableandSet-Variablecmdlets, but note that there are usually better alternatives, such as hashtables. See the linked duplicates for details.