I have a successful script that takes up some data analysis from local machine and exports a csv file at the end. No issues there.
Mn problem is that if someone has that file open, and at the same time script is writing to the file (I have -append switch), nothing gets written so I lose the data for that particular computer.
Any ideas how to force write the file even if it is open or in use? Thank you.
Functional export of existing array:
$NewCSVObject | Export-CSV '<fullpath>\CleanupResults.csv' -noType -Append
Have you tried setting that file to Read-Only? That will prevent anyone else from getting an opportunistic lock on it, and you can still append data to it by using the -Force switch.