Get Process Info, capture it and send it via email

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Post Reply
vrao5090
Posts: 1
Joined: Sat Sep 07, 2019 8:48 pm

Get Process Info, capture it and send it via email

Post by vrao5090 » Sat Sep 07, 2019 8:54 pm

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

User avatar
jvierra
Posts: 13732
Joined: Tue May 22, 2007 9:57 am
Contact:

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

Post by jvierra » Sat Sep 07, 2019 9:07 pm

What is it that you are asking? What is the question or what are the errors?

User avatar
venkirocs
Posts: 3
Joined: Mon Feb 01, 2016 3:08 am

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

Post by venkirocs » Mon Sep 09, 2019 3:55 am

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

Post Reply