I have a script that outputs data to a file using a basic Add-Content command. There's nothing special or unusual about how I'm using it and it works 99% of the time without any problems. But rarely, it will throw the error: "Add-Content : Stream was not readable." If I run the script again immediately, it will work with no problem.
The command is executed within a loop, such that the first time it runs, it creates the file (the file is created freshly each day.) On subsequent iterations of the loop, the file may be written to again.
My only guess as to what's going on is that the script is working so fast that occasionally the file system isn't quite ready to accept new input, but that's a total guess.
The full error is below, and even though it references an invalid argument, I don't believe that's what's actually going on (again, because it will run just fine immediately afterward in a different session.)
PS C:\WINDOWS> F:\Applications-Non JHA\Development\EOB\temp.ps1
Add-Content : Stream was not readable.
At F:\Applications-Non JHA\Development\EOB\temp.ps1:37 char:25
+ Add-Content -path ($OutputPath + $AcctNo + ".txt") -valu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (F:\Applications...put\3087832.txt:String) [Add-Content], ArgumentException
+ FullyQualifiedErrorId : GetContentWriterArgumentError,Microsoft.PowerShell.Commands.AddContentCommand
Thanks.