Solved

powershell

Posted on 2014-03-20
6
147 Views
Last Modified: 2014-04-05
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
Comment
Question by:tankergoblin
  • 2
  • 2
6 Comments
 
LVL 35

Expert Comment

by:Joseph Daly
ID: 39942626
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
 
LVL 69

Accepted Solution

by:
Qlemo earned 500 total points
ID: 39942760
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
 
LVL 7

Author Comment

by:tankergoblin
ID: 39955779
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
 
LVL 69

Expert Comment

by:Qlemo
ID: 39955877
0
 
LVL 7

Author Comment

by:tankergoblin
ID: 39958583
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

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

770 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