header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Check folders for content
Last Post 21 Apr 2010 06:20 AM 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 02: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.
    PoSherLifeUser is Offline
    Basic Member
    Basic Member
    Posts:364
    Avatar

    --
    09 Mar 2010 08:30 AM
    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 06:20 AM
    The Problem is solved ^^
    You are not authorized to post a reply.


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