Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Task Scheduler Sending *.log

Posted on 2014-03-05
8
Medium Priority
?
478 Views
Last Modified: 2014-03-10
I have been working on a script to do some vmware related things and when it completes it produces a .log with the time and date included in the filename.  I then have setup a task in the windows task scheduler to run the script and then the second step is to email me about it and include the file as an attachment.  The problem I have is with it consistently changing the filename I cannot point the task to just one file.

I attempted to tell it to send *.log and it did not send anything.  Has anyone attempted this or found a solution?
0
Comment
Question by:nextechexchadmin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 4

Expert Comment

by:Jason Ryberg
ID: 39906867
You could select the latest modified file in your scheduled script like so:

$Path = \\server\backup_directory
$latestlog = Get-ChildItem $Path | sort LastWriteTime | Select -Last 1

Open in new window

0
 

Author Comment

by:nextechexchadmin
ID: 39906933
I'm not sure I understand.  I have a scheduled task with two actions, first run my vmware script and second it to email me the log it produces. Inside the email action I cannot find a way to have it attach the newest file.
Task.PNG
0
 
LVL 4

Expert Comment

by:Jason Ryberg
ID: 39906963
Can you post the script you're having issues with?
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 

Author Comment

by:nextechexchadmin
ID: 39906976
I am not having problems with the script.  It is doing its task.  I just need the second action, the one sending the email, to attach a file correctly.

I have sent a pic of what the action of sending an email looks like.
email.PNG
0
 
LVL 4

Accepted Solution

by:
Jason Ryberg earned 120 total points
ID: 39907238
I would schedule a powershell script to send the email instead of using task schedule itself to send the email.  That way you can select the log file you want.

$Path = \\server\backup_directory
$latestlog = Get-ChildItem $Path | sort LastWriteTime | Select -Last 1

[string]$Emailbody = get-content C:\emailbody.txt
$attachments = $latestlog
$emailFrom = "admin@contoso.com"
$emailTo = "admin@contoso.com"
$subject = "Report"
$smtpServer = "10.10.254.1"
Send-MailMessage -To $emailTo -From $emailFrom -Subject $subject -Body $Emailbody -SmtpServer $smtpServer -Attachments $Latestlog

Open in new window

0
 

Author Comment

by:nextechexchadmin
ID: 39907923
I attempted this and I got the script to work without the attachment line, but when I include it I receive an odd message.  The dir where the report is generated is c:/power cli scripts/reports/ and the error is saying it cannot find the file in another dir, c:/users/ME/<FILE>.

The odd part is the file is correct, it can locate the correct and newest log but then when the time calls for it to grab it and email it is looks for it under my user dir.

Attached may explain more as well.
close.PNG
0
 
LVL 4

Expert Comment

by:Jason Ryberg
ID: 39907949
My apologies, you need the Fullpath of the attachment.  Change line 5 from the script above to:

$attachments = $latestlog.FullName
0
 

Author Comment

by:nextechexchadmin
ID: 39917720
It seems that works! Thank you for your hard work!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A small collection of useful tips and tricks for Windows 10 users that I decided to write as a result of recent questions that were asked and answered at Experts Exchange. Two short video tutorials included. Enjoy..
By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question