add-content produces stream not readable
Its an old post, but I run into a similar problem (using Set-Content
instead of Add-Content
).
In my case, the WriteAllText Method solved that issue.
This should solve it for you:
[System.IO.File]::AppendAllText($csv_file,$newline)
Here is a PowerShell approach if you don't want to call the windows API. Put in a try catch block within a do loop to retry until successful.
$isWritten = $false
do {
try {
Add-Content -Path $csv_file -Value $newline -ErrorAction Stop
$isWritten = $true
}
catch {
}
} until ( $isWritten )
}