$Result
is a collection of data rows, and foreach
can't use $_
(that's only for pipelined objects). You need to loop through the results and grab the Name
field from each row.
In your loop, you're overwriting $name
on each iteration, so you'll only output the results of the last Get-ChildItem
. You need to collect those results for output.
$ExeList = @();
Foreach ($Record in $Result) {
$ExeList += Get-ChildItem -path \\$($Record.name)\c$\ -recurse -filter *.exe
}
$ExeList|out-gridview;