Solved

POWERSHELL

Posted on 2014-10-01
7
79 Views
Last Modified: 2015-02-04
Hello
3 files are uploaded in /tmp All days
name of files :
YYYYMMDD_TIME_file1.xml
YYYYMMDD_TIME_file2.xml
YYYYMMDD_TIME_file3.xml

i d like to monitor if the 3 files are well in /tmp All days.  and if no , email alert

How Can i do with powershell please?

Regards
Laurent
0
Comment
Question by:LaurentLyon
7 Comments
 
LVL 29

Expert Comment

by:becraig
ID: 40355673
i d like to monitor if the 3 files are well in /tmp All days.  and if no , email alert


I am not sure what you mean, do you mean you want to know if 3 files matching the current date exist in the folder ?

e.g today is
20141001  so you want to check whether
20141001  _TIME_file1.xml
20141001  _TIME_file2.xml
20141001  _TIME_file3.xml
exists, and send an email if they do not ?
0
 

Author Comment

by:LaurentLyon
ID: 40355687
Hello
Yes , and All days :)
i just want to know if they are well here , and if one file is not here then email alert
thanks
0
 
LVL 79

Expert Comment

by:David Johnson, CD, MVP
ID: 40355910
$basepath = "c:\test\"
$filter = get-date -Format yyyy-mm-dd
$filter2 = "*.xml"
$filter = $filter + $filter2
$items = Get-ChildItem -Path $basepath -Filter $filter2
$items.count
if ($items.count -lt 4) {
Write-Output ("send email")
}

Open in new window

0
 

Author Comment

by:LaurentLyon
ID: 40356685
Hello , thanks David ,

I d prefer that the script email an alert with the files missing ?


Regards
Laurent
0
 
LVL 14

Accepted Solution

by:
Justin Yeung earned 500 total points
ID: 40362613
$path = "c:\test"
$date = get-date -Format yyyy-mm-dd
[array]$files = @("$date*file1.xml","$date*file2.xml","$date*file3.xml")
foreach ($file in $files)
{
if (!(get-childitem -path $path -name $file))
{
send-mailmessage -from someone@some.com -to someone@some.como -subject "no file found" -body "file with name $file is not found in here" -smtpserver yoursmtp
}

}

Open in new window

0

Featured Post

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This article explains how to install and use the NTBackup utility that comes with Windows Server.
This tutorial will walk an individual through locating and launching the BEUtility application to properly change the service account username and\or password in situation where it may be necessary or where the password has been inadvertently change…
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…

803 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