Avatar of techdrive
techdrive
Flag 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.
Powershell

Avatar of undefined
Last Comment
chrismerritt

8/22/2022 - Mon
x-men

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}
x-men

$(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
chrismerritt

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23