Powershell script for counting files and emailing results

5 pts.
Tags:
PowerShell Scripts
I need to find a script that will count files in a directory and return results via email if they exceed a certain amount. I am trying to automate a manual process. I am not a Powershell expert, but I am trying to learn. Can anyone point me in the right direction?

Software/Hardware used:
Windows 2008 R2 on VMware 4.1

Answer Wiki

Thanks. We'll let you know when a new response is added.

This should do it. This is provided as is and with no warranty. if you need anything else contact me at colin@dbyay.com

$path = “Path to check”
$files = ls $path 
$fcount = $files.count
if{$fcount -gt 5)
{
Send-MailMessage -SmtpServer “yourserver.domain.com” -To “email address” -From “from address” -Subjuct “files in $path exceeded threshold” -Body “File count in path is $fcount”
}

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following