Solved

PowerShell Script failing

Posted on 2014-09-18
3
43 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
3 Comments
 
LVL 3

Accepted Solution

by:
Phil Bossman earned 500 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In this post, we will have a look on how to install Exchange Server 2013 from command prompt, instead of using the graphical user interface. Below are the steps that are to be performed to install Exchange Server 2013. 1. Domain Controller and…
Microsoft Outlook provides an easy way to recover permanently deleted items. When you empty the Deleted Items or simply deleted an Outlook data items using shift+Del key then it can be recovered using Registry Key settings.  Caution- Wrong Registry…
The purpose of this video is to demonstrate how to use PicMonkey software to customize images for a Mailchimp campaign. Picmonkey is free and simple online software which can be used by users who don’t have robust editing software such as Photoshop,…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now