Skip to content

Instantly share code, notes, and snippets.

@emiliano-poggi
Created April 4, 2011 20:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emiliano-poggi/902424 to your computer and use it in GitHub Desktop.
Save emiliano-poggi/902424 to your computer and use it in GitHub Desktop.
POSH: For each constructs
# foreach statement
foreach ($ps1 in ls -filter $home\*.ps1) {$ps1.length/1024}
# foreach inside the pipeline
ls -filter $home\*.ps1 | ForEach-Object -process {$_.length/1024}
# foreach inside the pipeline omitting -process
ls -filter $home\*.ps1 | ForEach-Object {$_.length/1024}
# foreach inside the pipeline using foreach alias
ls -filter $home\*.ps1 | foreach {$_.length/1024}
# foreach inside the pipeline using % alias
ls -filter $home\*.ps1 | % {$_.length/1024}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment