I suspect this is the culprit $att = new-object Net.Mail.Attachment($filelocation)
I'd try adding $att = $nul to the end of the script. ________________________________ From: Greg Mulholland [mailto:g...@krystaltek.com] Sent: Thursday, January 08, 2009 7:32 PM To: MS-Exchange Admin Issues Subject: powershell script locking output file Hi guys I have a powershell script that runs exchange commands and outputs to a html file and emails the report. However it seems something is locking the file cos the subsenquent times I run the script I get 'the process cannot access the file because it is in use by another process. The script is not ready for pirme time (yet) but its really annoying changing the filename everytime I want to run the script. I was using a dispose command at the end of the another script I wrote e but this doesn't seem to work on this one. Anyone have any ideas. This is the guts of what the script does so far. ####################### # Exchange Commands # ####################### Get-Exchangeserver -identity mbx-au | ConvertTo-HTML Name,Site,ServerRole,Edition,AdminDisplayVersion -title "Process Information" -body "<h2>Information about the processes running on the computer.</h2>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation Get-Message -Filter {FromAddress -like "*...@atex.com"} | ConvertTo-HTML -title "Queued Mail" -body "<h2>Queued Mail.</h2>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation Get-MailboxStatistics -server mbx-au | where {"IssueWarning","ProhibitSend","MailboxDisabled" -contains $_.StorageLimitStatus} | Sort-Object TotalItemSize -Descending | ConvertTo-HTML DisplayName,TotalItemSize,StorageLimitStatus -title "Mailboxes Over Limit" -body "<h2>Mailboxes Over Limit</h2>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation ###################### # E-mail HTML output # ###################### if ($enablemail -match "yes") { $msg = new-object Net.Mail.MailMessage $att = new-object Net.Mail.Attachment($filelocation) $smtp = new-object Net.Mail.SmtpClient($smtpServer) $msg.From = $mailfrom $msg.To.Add($mailto) $msg.Subject = "Exchange Housekeeping Script" $msg.Body = "Exchange Housekeeping Script" $msg.Attachments.Add($att) $smtp.Send($msg) } e but this doesn't seem to work on this one. Anyone have any ideas ************************************************************************************************** Note: The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. ************************************************************************************************** ~ Ninja Email Security with Cloudmark Spam Engine Gets Image Spam ~ ~ http://www.sunbeltsoftware.com/Ninja ~