header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

[August 25th, 2008] Check the home page regarding PowerShell related news from a brand new sponsor: Idera

Subject: email function locks file
Prev Next
You are not authorized to post a reply.

Author Messages
frejenUser is Offline
New Member
New Member
Posts:8

07/15/2008 12:59 AM  

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

JaykulUser is Offline
Shell User
Shell User
Posts:32


07/15/2008 6:09 AM  
You need to .Dispose() the $message when you're done.

See the example here: http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx
frejenUser is Offline
New Member
New Member
Posts:8

07/15/2008 6:34 AM  
Thank you Jaykul!
You are not authorized to post a reply.
Forums > Using PowerShell > General PowerShell > email function locks file



ActiveForums 3.7
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer