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

~ Ninja Email Security with Cloudmark Spam Engine Gets Image Spam ~
~             http://www.sunbeltsoftware.com/Ninja                ~

Reply via email to