I really stink at scripting and I need your help. I pieced together this script from several places on the internet and it works, until I enable my IF statement...
I'm just trying to get a count of files of a folder from a UNC path, and if it's over a specified amount, then I want it to send an email letting me know with the current count.
However, if I uncomment the if ($count -gt 50)
part, then I won't get an email if the count is over 50.
I don't know how to make the ".Count" a variable for me to use elsewhere in the script. Can someone please help?
Then I'll need to figure out how to run it. Was thinking just a scheduled task in windows and have it run every few minutes or something, but if you have any better ideas, I'd like to hear them!
$FolderList = @(
"\\server\path\test"
)
$Body = ($FolderList | ForEach-Object {
"Check to see if Sweep Service is running, file count for '$($_)': " + (Get-ChildItem -Path $_ -File -ErrorAction SilentlyContinue | Measure-Object).Count
}) -join "`r`n"
#if ($count -gt 50)
#{
$From = "me@you.com"
$To = "me@you.com"
$Subject = "Sweep Checker"
$SmtpServer = "webmail.you.com"
Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SmtpServer
#}