Solved

Task Scheduler Sending *.log

Posted on 2014-03-05
8
465 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
  • 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

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 30 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

This article will show you how to create an ISO CD-ROM/DVD-ROM image (*.iso), and MD5 checksum signature, for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5). It's a good idea to compare checksums, because many installations fail because of a corr…
When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This Micro Tutorial walks you through using a remote console to access a server and install ESXi 5.1. This example is showing remote access and installation using a Dell server. The hypervisor is the very first component of your virtual infrastructu…

810 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