1
votes

I have a security question regarding a script that I have. My script creates two temporary CSV files, and after I run the script those files are deleted. Now, when the script crashes or the user stops it, those files remain in to the folder. How can I make sure that those files will get deleted if this happens?

I was thinking about using the windows temp folder "$TempDir = [System.IO.Path]::GetTempPath()", but this will not make any difference since the temp folder is renewed after boot time.

Any thoughts/suggestions?

1
Have you considered writing these files to a restricted folder, i.e. to a location where only limited number of people will have access to? - Amnon Shochot
I have, but my issue is that when the program starts from the beginning, It will eventually find the temp file and use it. I would like to avoid that. - user01230
So why not starting your script with cleaning up the left overs of previous executions? - Amnon Shochot
That is actually a good way to go. I did not think of it haha. Thank you @AmnonShochot - user01230
Summarized our discussion in an answer below. - Amnon Shochot

1 Answers

1
votes

One solution to your problem may be to write the temporary files to a location that only a limited number of people have access too.

Then, if the existence of these files may affect future executions of the script then a good practice would be to first check for left-overs from previous executions of the scripts, and if there are start the script with cleaning these up.