Foreach-object v/s Foreach (Powershell)
Looping is a core of any code or script and we have to make sure we have to do it correctly. One interesting question everyone asks which is a better loop when you want to run a specific command in several computers and whole heartedly we choose Foreach() loop. Foreach is one of the rising star when chosen between invoke-commad and where { }. Advantage of having foreach is that we can store value under one string in excel which is a boon. Likewise we get 2 different option while choosing foreach () , 1 is foreach itself and other is foreach-object. But when you see the object it looks similar doesn’t it. Well I have performed one test so that we can pick our winner.
Let’s dive into it…
$a=Get-ChildItem –File C:\users\dhrub\ -Recurse
$time = (Measure-Command {
$a | ForEach-Object {
$_
}
Want to know the Result Click here — >