techdrive
asked on
output data to file
I have ran numerous scripts to get information and for the most part I pipe it or redirect this to a file. What I notice is (especially on looping statements) that the script would run , save everything in memory and at the end would place the results of the script in the file. Is there a way for example to have the data to be writtten to the script each time it goes into iteration instead of waiting until the end. If so please and please do provide some examples, thanks.
$(for ($i = 1; $i -lt 10; $i++) {$i}) | Out-File -filePath file.txt
same as:
$(for ($i = 1; $i -lt 10; $i++) {$i}) > file.txt
same as:
$(for ($i = 1; $i -lt 10; $i++) {$i}) > file.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$(for ($i = 1; $i -lt 10; $i++) {$i}) | Out-File -filePath file.txt
this will write on each $i:
for ($i = 1; $i -lt 10; $i++) {$i >> file.txt}