• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

powershell

Hi,

How to write a script to calculate how many files in a folder every 1 min. If files is more than 10 then send an email to administrator.

Also how to get cpu utilization in Linux OS... do i need snmp to do so?
0
tankergoblin
Asked:
tankergoblin
  • 2
  • 2
1 Solution
 
Joseph DalyCommented:
The below powerhsell script should work for the count.

$dir = gci c:\directory\directory
$count = $dir.count
if ($count -gt 10) {Send-MailMessage -to "user@domain.com" -Subject "Warning message" -from user@domain.com -smtpserver server.domain.com -body "message body"}
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
You can't use PowerShell directly to get the Linux stats. SNMP might indeed be supported, if you can locate the correct MIB path for your counters. That should be a different question, as it targets Experts not listening to PowerShell questions ;-).

Regarding the count, the above code shows some basics, but the loop is missing. I assume the task should run until 10 files were found, because sending a mail every minute won't be something you want to have implemented for sure.
while ( (get-childitem c:\folder\files*).Count -lt 10 )
{
   sleep 60
}
Send-MailMessage -To 'You@YourDomain.Com' -From 'You@YourDomain.Com' -SmtpServer mx.YourDomain.com -Subject 'File limit reached'

Open in new window

This will stop as soon as 10 files were found.
0
 
tankergoblinAuthor Commented:
i was been told that powershell almost can do everything you can think of... so are you sure powershell is not compatible to linux platform?
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
0
 
tankergoblinAuthor Commented:
is that mean we can or cannot get information from other platform? if can pls show me some link that show some code on it...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Building an Effective Phishing Protection Program

Join Director of Product Management Todd OBoyle on April 26th as he covers the key elements of a phishing protection program. Whether you’re an old hat at phishing education or considering starting a program -- we'll discuss critical components that should be in any program.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now