Why these 2 are different, what else should i calculate to get the memory usage of a particular process
This isn’t really a PowerShell question so much as basic Windows OS. The GUI in this case - like many others - is providing a nice cushy layer on top of what’s really happening in the OS.
There’s a good description of working set at https://msdn.microsoft.com/en-us/library/windows/desktop/cc441804(v=vs.85).aspx. Working set represents the amount of pageable virtual memory pages that are currently in RAM.
Windows processes consist of two kinds of memory: what’s in physical RAM right now, and what’s been swapped to the page file. Some of what’s in RAM is pageable, meaning it’s eligible to be swapped, and non-pageable, which isn’t eligible. Which is it you’re looking to measure?
i am looking to measure whatever a process takes as memory
There are a lot of different kinds of memory used by a process. Look at the properties at https://msdn.microsoft.com/en-us/library/system.diagnostics.process(v=vs.110).aspx - this explains what the different memory types are. You can decide which ones are the ones you want, and add them together as needed.
if i want to get the same data as in task manager, which one should i pick… in all forums these are not mentioned rightly and no one other than You DON can tell me this
Consider the possibility that Task Manager isn’t actually giving you truthful information for the job task you’re trying to perform. And what Task Manager show you isn’t just one value. It does some addition under the hood and shows you a composite. That’s why I don’t like its numbers.
Personally, I don’t think the data in Task Manager is useful. I tend to care about Physical Memory, which is the amount of RAM actually in use. I don’t care so much about memory that’s been swapped out to disk. Why would I? Windows doesn’t even aggressively recycle that memory, so it’s not a useful indication of much.
Because you’re really not asking a PowerShell question, you might consider posting on ServerFault.com. Explain the job task you’re trying to do, and get some opinions on what memory counters would be useful for that job task. Without knowing what you’re trying to DO, it’s difficult to tell you what you should be looking at. ServerFault will get you a much broader range of input and opinions.