What you haven??™t seen before is the break statement. We??™ll discuss this in the next section,
but essentially it tells Windows PowerShell to stop processing the rest of the potential
switch conditions, which makes sense since we??™ve already found a match.
448 Microsoft Windows Server 2008 Administration
GOING LOOPY
One of the main reasons administrators write scripts is to automate repetitive tasks??”after
all, you have more important things to do than renaming a bunch of files or setting permissions
to a folder structure. Computers are excellent for these kinds of tasks, because
they don??™t get tired, they don??™t complain, and in general they can do this around the clock,
even while you are sound asleep. Another key construct in any scripting language is the
ability to create loops in your script. A typical example would be a script to go through all
the files in a folder and rename each file so that it is prefixed by the string backup-.
Loops are quite simple, but they are one of the biggest reasons why scripts ???go wild.???
In general, the loop has a condition that defines when it should stop doing whatever it is
that it??™s doing. Sometimes coding or logic errors result in a state in which that condition
is never met and your script gets caught up in an endless loop that keeps on going, since
the condition to make it stop will never happen. You can implement loops in Windows
PowerShell in four ways: For, Foreach, While, and Do??¦While statements.
Pages:
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477