I need to make kind of script or program which restarts the required windows application when it uses more RAM than 1GB for example. I want to use powershell, but got stuck on getting RAM usage of given app into a variable. I tried $OutputVariable = (Get-Process %processname% | Select-Object WS) | Out-String
but that doesn't work, cause I need the value only.
Asked
Active
Viewed 90 times
1

Andrew reckoner
- 31
- 2
-
3Are you sure you really want to do this!? It would be better to fix the application to remove the memory leak or remove in memory objects. – alastairtree Dec 04 '15 at 17:03
-
That's third-party app, unfortunately I can't fix that, thanks for advice anyway! – Andrew reckoner Dec 04 '15 at 21:22
1 Answers
1
(Get-Process explorer).WS
will give you the value only. But I guess you'd better fix that memory leak instead.
see
What are ways to solve Memory Leaks in C#
What strategies and tools are useful for finding memory leaks in .NET?
How to use IDisposable to fix memory leaks
among others

Community
- 1
- 1

sodawillow
- 12,497
- 4
- 34
- 44
-
You could do `$OutputVariable = ((Get-Process %processname%).ws/1048576)` to get you from KB to GB. – Nate Dec 04 '15 at 17:25
-
-
It *seems* this is available even in PS2 according to a few searches – sodawillow Dec 04 '15 at 17:38
-
Yep, you're right. I was recycling code and setting a variable instead of running the process. Ah, details. :) – Nate Dec 04 '15 at 17:42