Hi,
I am experiencing a problem with file locks in some of my scripts. Yesterday i went mad and started breaking one of the scripts down to justa few lines and i still got the error message telling me that "process can not access file because it is being accessed by another process". The cmdlets that throws that error is remove-item and set-content, i want to use them in order to clean an old logfile.
One of the scenarios is the following. The script run a couple of times each day, and adds some of its output to a logfile. Each sunday i want to email the logfile and remove it. So i have a function for emailing and i have located the lock problem to something inside that function. I would guess on the Attachment line, here is the code for my function http://pastebin.com/m5cc977ff (did not find any code tags for the forum post)
if i comment out my call to that function i can use remove-item on the attachment/logfile. But if the email has been sent i can not remove it. Any known problem with file locks with anything on line 14 in pastebin? The email is delivered as it should be with attachment and all.
Cheers,
Frej |