I'm question.
I get process name througth powershell script using c#. But, i did not get value because process name contains whitespace.
How can I get value to contains whitespace in powershell using c#?
I'm question.
I get process name througth powershell script using c#. But, i did not get value because process name contains whitespace.
How can I get value to contains whitespace in powershell using c#?
You don't need PowerShell to get processes.
This sample line gives you the ID/Name for all processes with ID 21952 (although I suspect you won't have one with ID 21952).
var processes = System.Diagnostics.Process.GetProcesses().Where(p => p.Id == 21952).ToDictionary(p => p.Id, p => p.ProcessName);
To remove that filter:
var processes = System.Diagnostics.Process.GetProcesses().ToDictionary(p => p.Id, p => p.ProcessName);
You could do the following directly in C#
using System.Diagnostics;
...
int pid = 21952;
Process localById = Process.GetProcessById(pid);
Console.WriteLine($"Process name for pid {pid}: '{localById.ProcessName}' '{localById.MainModule.FileName}'");