Get Process Info, capture it and send it via email

Ask your 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.
This topic is 4 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
vrao5090
Posts: 1
Last visit: Sat Sep 07, 2019 8:54 pm

Get Process Info, capture it and send it via email

Post 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
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

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

Post by jvierra »

What is it that you are asking? What is the question or what are the errors?
User avatar
venkirocs
Posts: 3
Last visit: Sat Dec 07, 2019 6:06 am

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

Post 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
This topic is 4 years and 6 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked