Solved

POWERSHELL

Posted on 2014-10-01
7
80 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 80

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Synchronize a new Active Directory domain with an existing Office 365 tenant
Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
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 steps necessary to enable the VMware\Hyper-V licensed feature of Backup Exec 2012. In addition, how to add a VMware server and configure a backup job. The first step is to acquire the necessary licen…

790 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