Forum Discussion
D_Lewis79
Jun 17, 2021Copper Contributor
Foreach loop output file
Hi all, Some expert help please... I am really happy with how a foreach loop is working as I would expect it but I can't find a solution to export the results to a text file. The code is below: ...
farismalaeb
Jun 19, 2021Steel Contributor
Hi
You will need to add a variable before the Foreach type Array
$MyResult=@()
and in the Foreach loop, add the result to this variable.
$MyResult+="The Thing you want to add"
And After the ForEach loop, you will need to Export the content as text or what ever you want using
Out-File or Export-CSV ...
https://powershellmagazine.com/2013/02/04/creating-powershell-custom-objects/