Assigning Multiple Variables

Share |

Join PowerShell.com!
Subscribe to Feed

PowerShell eBook
Sign up for
Your PowerTip of the Day:

Award-winning PowerShellPlus


Admin Guide to PowerShell Remoting


Mastering PowerShell eBook

In PowerShell, you can initialize multiple variables in just one line. The following line sets all variables to the value 1:

$a = $b = $c = $d = 1

To swap variables, list variables as comma-separated lists (actually, PowerShell treats your lists internally like arrays):

$a = 1; $b = 2
$a, $b = $b, $a
$a; $b

Posted Jan 18 2009, 08:00 AM by ps1
Copyright 2012 PowerShell.com. All rights reserved.