I'm trying to figure out how to view the services tied to running processes in PowerShell. In Command Prompt, I can easily run `tasklist /svc` to get this info, but I want to achieve the same result using PowerShell and have it come back as objects. I've even created a function to do this, but I'm curious if there's a more straightforward way or if I'm missing something with built-in commands.
4 Answers
You might also want to check out PowerShell Crescendo. It's a module that helps you create cmdlets to transform outputs into objects, which could give you a nicer experience with cmd outputs like `tasklist /svc`. It might streamline your function's output too!
You could use `Get-CimInstance win32_service -Filter "processid != 0" | Group-Object ProcessID` to identify shared processes too. It shows which PIDs are hosting multiple services. Combine that with your function for a full picture of processes and their related services.
Good point! That would let me see the shared services, but I still need my function to show processes with their services. Thanks for the tip!
Another way is to utilize the `Win32_Process` Cim instance and filter based on `ParentProcessId`. However, this only gives the parent processes, not the services you're interested in that are tied to specific process IDs.
True, but the `ParentProcessId` won't capture the services under the process like `svchost.exe`. You're better off staying with your original approach!
It seems like you're looking for an alternative to the built-in `Get-Service` and `Get-Process` commands. The thing is, while those commands work well on their own, they won't show you services tied to processes like `svchost.exe`. What you're doing with your function to get that extra detail from `tasklist /svc` is a good approach since PowerShell doesn't have a direct equivalent for that.
Exactly! Processes like `svchost.exe` can host multiple services, so without your custom function, you'd miss that connection. Keep up the good work!

I’ve heard about Crescendo! I’m hesitant because I prefer working directly with .NET classes like you are. But it could be a simpler way to handle cmd output if set up correctly.