PowerShell - Farewell to For

JMH

Emeritus, Contributor
Joined
Apr 2, 2012
Posts
7,197
In my last article (Goodbye, Goto), I described how batch files handle common iteration (repeating or looping) and subroutines using the Goto and Call commands, and the most common PowerShell language constructs that replace those commands. Batch files have one last iteration command command that you still need to know how to replace in PowerShell: The For command.

The For command was added to Command.com in DOS over 30 years go, and originally it allowed you to run a command for each file in a set (hence the name). When Microsoft released Windows NT, they extended the For command in Cmd.exe into a more general command that can iterate files, directories, text files, and the output of commands. Over time, the Cmd.exe For command has turned into a complex command that has a number of tricky syntax quirks. In this article I’ll discuss how you can can replace each feature of the For command in PowerShell.
PowerShell - Farewell to For | Windows content from Windows IT Pro
 

Has Sysnative Forums helped you? Please consider donating to help us support the site!

Back
Top