In most programming languages the conventional way to swap the value of two variable is to use a third variable.

PS> $a=1 PS> $b=2 PS> $temp = $a PS> $a = $b PS> $b = $temp PS> "<code>$a=$a,</code>$b=$b" $a=2,$b=1

In Windows PowerShell it is much easier. We can use multiple assignments to perform the same operation in less code and without a third variable.

PS> $a=1 PS> $b=2 PS> $a,$b = $b,$a PS> "<code>$a=$a,</code>$b=$b" $a=2,$b=1

You can also swap multiple variables. In the following example, *$a* will swap its value with *$c*, *$b* will swap its value with *$d*, and so on and so forth.

PS> $a=1 PS> $b=2 PS> $c=3 PS> $d=4 PS> $a,$b,$d,$c = $c,$d,$a,$b PS> "<code>$a=$a,</code>$b=$b,<code>$c=$c,</code>$d=$d" $a=3,$b=4,$c=2,$d=1