Does anyone have a Powershell script that will automatically email the log file from the FSA Archive run?

This issue has been solved. See solution.
tluncefo's picture

I would like to email the log file generated every time my scheduled FSA task completes.  I know I can do it manually, but I would like to automate the process.

LanceChase's picture

I would use a program

I would use a program like Blat.exe that can be configured with you exchange server. Then schedule to run at a certain time everyday to email you and include the log file.

Let me know if you need more assistance.

tluncefo's picture

We do not have Exchange in

We do not have Exchange in the environment.

Rob Wilcox's picture

Blat..... I believe blat can

Blat.....

I believe blat can send email by connecting to any SMTP service via TCP/IP.

Thanks
Rob Wilcox
EV Engineering Support

tluncefo's picture

My issue is how to script which file to send

I am fairly certain I can use Powershell or Blat to send the file.  My issue is how to script which file to send.  Each time the FSA Archive job runs it creates a new directory based on the time the job finishes - which can be different every time.  The file name can vary based on whether or not the job completely finishes or not.

I need to be able to automatically email out the log file from every archive job run - every time it runs.

PJuster's picture

can you not schedule a script

can you not schedule a script to run after your scheduled archive run to zip of the contents of the \reports\FSA\File System Archiving Task\ArchiveRunNow\completed\ email it across and then move the contents of the same folder somewhere or if you are confident the script will work delete the files and folders.

Or can the script not check for the most recent folder in this location and then email the contents across.

All these things are possible it just having the time and programming skill. 

Rob Wilcox's picture

Rudimentary example follows

Solution

Rudimentary example follows :

I spent 15 minutes or so writing this, I'm sure it could be tidied up a fair amount, but it "does the job" :

A few things that you'll need to do :-

a) modify the $from and $to for your domain
b) modify the start path depending on the name of your task (mine is called ppts on exch1)
c) modify the start path depending on whether you want to monitor/email Scheduled runs or Run-now runs.
d) modify the SMTP server (mine is smtp-server.yourdomain.local)

#* Send mail

Write-host "`nSending mail"

 

$from=new-object system.net.mail.mailaddress "monitoring@yourdomain.local";

$to = new-object system.net.mail.mailaddress "you@yourdomain.local";

 

#* Find the attachment to send

$startpath = "C:\Program Files\Enterprise Vault\Reports\FSA\ppts on exch1\ArchiveScheduled\Completed"

#* $startpath = "C:\Program Files\Enterprise Vault\Reports\FSA\ppts on exch1\ArchiveRunNow\Completed"

 

$folder = get-childitem($startpath) | sort-object Name -Descending | select-object -first 1

$fullfolder = $startpath + "\" + $folder.name

 

Write-host "`nLooking in folder name : " $fullfolder

 

$filename = get-childitem($fullfolder)

$att=$fullfolder + "\" + $filename.name

 

Write-host "Attachment we will add is : " $att

 

 

$mail=New-object system.net.mail.mailmessage $from, $to

 

$mail.subject = "test message";

$mail.body = "some text";

$mail.attachments.add($att);

$smtp = new-object system.net.mail.smtpclient("smtp-server.yourdomain.local");

 

"`nSending message to {0} by using SMTP host {1} port {2}." -f $to, $smtp.host, $smtp.port

$smtp.send($mail);
 

Thanks
Rob Wilcox
EV Engineering Support

tluncefo's picture

Thanks Rob

That did the trick.  I had most of the script written, just not the part where it selects the latest file.