#PSTip Initializing multiple variables at once

Here’s another cool variables tip. Say you want to initialize a few variables to a specific value.¬†Instead of doing:

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

Try PowerShell’s assignment expressions!

PS> $a=$b=$c=$d = 1
PS> $a,$b,$c,$d
1
1
1
1

About the author: Shay Levy

Shay Levy is a Co-founder and editor of the PowerShell Magazine. He is a multiple-year recipient of the Microsoft MVP award, and a Microsoft Certified Trainer (MCT). Shay often covers PowerShell related topics on his blog and you can also follow him on Twitter at @ShayLevy

Related Posts

%d bloggers like this: