can I include root folder to get-childitem output programmatically?
get-childitem $root -recurse | foreach-object -begin { $arr = @((get-item $root).fullname) } -process { $arr+= $_.fullname } -end { $arr }
Using foreach-object cmdlet's begin switch, we do some work before handling the objects from get-childitem: we create an array and put the filepath of the root in there.
Then for each object in the pipeline, we append its filepath to the array.
Finally, we output the array to the pipeline.
@(gi e:\mytree) + @(gci e:\mytree -r) | select fullname
@(..) forces the return value from each expression to be an array