Quantcast
Channel: Windows PowerShell Forum
Viewing all articles
Browse latest Browse all 2562

redirect loop output to file

$
0
0

hello i'm trying to study powershell and need help in incredibly simple operation. I work in bash and never thought that will stuck on redirecting loop output to file

i tried :

for ($i=0; $i -le 10; $i++) {write-host $i} )  > file 

or | out-file file
or | Tee-Object file



tried to make it through function

function fps () {for ($i=0; $i -le 10; $i++) {write-host $i} )}  > file

or | out-file file
or | Tee-Object file

tried to pipe redirection inside function

{write-host $i | out-file file

or

Tee-Object file

}

and didn't get any result except empty output file

How come that it doesn't work??? What crazy logic should i use to just get a file with {1..10}???

I googled about ps loop redirection but found only weird and way to much complicated solutions for such a basic stuff!!!

Please help my guys!!!


Viewing all articles
Browse latest Browse all 2562

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>