Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

PowerShell Script failing

Posted on 2014-09-18
3
Medium Priority
?
100 Views
Last Modified: 2016-06-13
Hi Expert,

I need help here I'm using this PS script for sending email if any new files arrived in a folder, not sure why I can't get any email when adding files in folder and run the script.
Param (
	[string]$Path = "D:\ABC\",
	[string]$SMTPServer = "172.31.32.203",
	[string]$From = "abc.efg@abc.com.au",
	[string]$To = "abc.efg@abc.com.au",
	[string]$Subject = "New File Uploaded to FTP Site"
	)

$SMTPMessage = @{
    To = $To
    From = $From
	Subject = "$Subject at $Path"
    Smtpserver = $SMTPServer
}

$File = Get-ChildItem $Path | Where { $_.LastWriteTime -ge [datetime]::Now.AddMinutes(-1) }
If ($File)
{	$SMTPBody = "`nThe following files have recently been added/changed:`n`n"
	$File | ForEach { $SMTPBody += "$($_.FullName)`n" }
	Send-MailMessage @SMTPMessage -Body $SMTPBody
	
}

Open in new window


I added SMTP server and use the default IP address, and port 27. I open outbond connection in firewall for port 27.
Can someone help here.
Thanks in advance
0
Comment
Question by:adnankh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 3

Accepted Solution

by:
Phil Bossman earned 2000 total points
ID: 40331877
This code works for me out of the box.

Add some "Write-Verbose" code to find whats happening

Write-Verbose $File.FullName -Verbose

Open in new window

just after the $File assignment

Write-Verbose "Sending Email" -Verbose

Open in new window

Inside the If block

Open the powershell console,  cd to the script's path.  Add a file, then run the script and see what verbose output shows
0
 

Author Comment

by:adnankh
ID: 40331904
Cool Thanks I check it and back to you soon
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Article by: Dermot
The life of crime is over for 22 year-old Christian Ian Salvador, a student from Isabela State University in the Philippines.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

715 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