Link to home
Start Free TrialLog in
Avatar of techdrive
techdriveFlag for United States of America

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.
Avatar of x-men
x-men
Flag of Portugal image

this will write after processing:
$(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}
$(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
ASKER CERTIFIED SOLUTION
Avatar of chrismerritt
chrismerritt

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial