Page 1 of 1

Get Process Info, capture it and send it via email

Posted: Sat Sep 07, 2019 8:54 pm
by vrao5090
Hello,

Trying to get a quick help. Need to get w3wp.exe process memory consumption in GB and send the info via an email. Here is the pseudo code:

$serverlist = c:\temp\serverlist.txt
Get-Process --ComputerName $serverlist -Name w3wp | Out-File -FilePath c:\temp\test.txt
$From = "EmailAddress@gmail.com"
$To = "address1@abcde.com;address2@abcde.com;address3@abcde.com"
$Attachment = "C:\temp\test.txt"
$Subject = "Process Info"
$currenttime=Get-Date
$Body = "Please see attached file for more info about IIS process taken at"$currenttime
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
Send-MailMessage -From $From -to $To -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -Attachments $Attachment

Once the code works, I would like to schedule it to run inside the task scheduler of windows server and run it at scheduled intervals which means, the user is logged off when the script runs in the background.

Will greatly appreciate your help on this.

Thanks.

Victor

Re: Get Process Info, capture it and send it via email

Posted: Sat Sep 07, 2019 9:07 pm
by jvierra
What is it that you are asking? What is the question or what are the errors?

Re: Get Process Info, capture it and send it via email

Posted: Mon Sep 09, 2019 3:55 am
by venkirocs
you can use the Task Scheduler's "Run As" option to provide username & password.
This will help to run the script even if no one is logged on