header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

We have a new sponsor!  Introducting Pragma Systems.  See the home page for details.

Check folders for content
Last Post 21 Apr 2010 02:20 PM by Neocore. 2 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Resolved
NeocoreUser is Offline
New Member
New Member
Posts:8
Avatar

--
09 Mar 2010 10:49 AM  
Hi,

I am new here and this is my first experience with Powershell.
My task is it to write a script which looks in a specified Directory for Files and should report me if there are files.

This is my script:

function Send-Mail
{
   param($SmtpServer,$From,$To,$Subject,$Body)

   $smtp = new-object system.net.mail.smtpClient($SmtpServer)
   $mail = new-object System.Net.Mail.MailMessage
   $mail.from= $From
   $mail.to.add($To)
   $mail.subject = $Subject
   $mail.body= $Body
   $smtp.send($mail)
}

$Directory = "Path to folder"

$MailForm = "Sender Address"
$PSEmailServer = "SMTP Server"

$Data = get-childitem $Directory -force -name
$Counter = $Data.count
if($Counter -gt $null)
 {
   $Subject="Your Subject!!!"
   $Body = "Your Text!!!"
   Send-MailMessage -From $MailForm -To $MailForm -Subject  $Subject -Body  $Body
 }




The problem with my script is that it only runs if the folder contains more then one data file but it should report me if there are data files in it or not considering all data files.
Cruisader03User is Offline
Basic Member
Basic Member
Posts:243
Avatar

--
09 Mar 2010 04:30 PM  
From what you described that you want the problem is that you ONLY send the message when $counter -gt $null (if there is data). The bottom section should look like this:

if($Counter -gt 0)
{
$Subject="You Have Data"
$Body = $Data
}
else {
$Subject="You Don't Have Data"
$Body="You Don't Have Data"
}
Send-MailMessage -From $MailForm -To $MailForm -Subject $Subject -Body $Body
When at first you don't succeed Step-Into

http://theposherlife.blogspot.com
http://www.jandctravels.com

NeocoreUser is Offline
New Member
New Member
Posts:8
Avatar

--
21 Apr 2010 02:20 PM  
The Problem is solved ^^
You are not authorized to post a reply.

Active Forums 4.1
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 footer
footer