Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Send email when new file is created in a folder

$
0
0

Main idea here is to send an email when i new file or folder is created in some path.

for $body it should say new file detected: FILENAMEHERE

$path = "Z:\"
$limit=$(Get-Date).AddMinutes(-1)
$sendmail= $To="me@domain.com";$From= "administrator@domain.com";$Subject = "new file created";$Body= "New File Detected";$Message = New-Object System.Net.Mail.MailMessage $From, $To, $Subject, $Body;$smtpServer = "smtp.domain.com";$smtp = new-object Net.Mail.SmtpClient($smtpServer);$smtp.EnableSsl = $false;$smtp.Credentials= New-Object System.net.NetworkCredential("administrator@domain.com","password");$smtp.Send($message);
Get-ChildItem -Path $path -Recurse -Force | Where-Object { !$_.PSIsContainer -and $_.CreationTime -lt $limit} | Then {$sendmail}


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>