Add-content creates a stream that is not readable

I have a PowerShell script that dumps a gazillion lines into a csv file when processing very large XML.

While reading an xml read, I write each line to the csv file as follows:

$newline | add-content -path $csv_file 

This works 99%, but sometimes I see that in the "add-content: stream was not readable" log for 1 or 2 elements from gazillions I assume because he is busy writing the last line.

Any permission?

+5
source share
1 answer

This is an old post, but I ran into a similar problem (using Set-Content instead of Add-Content ). In my case, the WriteAllText method solved this problem.

This should solve it for you:

 [System.IO.File]::AppendAllText($csv_file,$newline) 
+5
source

Source: https://habr.com/ru/post/1208618/


All Articles