Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Sort running services

$
0
0

Well.. okay. But you’re talking about different things.

A service IS NOT a scheduled task. You don’t schedule services. They start automatically at boot, or can be started manually, or are completely disabled. When a service is running, it does show up in Task Manager. Get-Service will not let you make the connection to a process, though.

Get-WmiObject Win32_Service -filter "state = 'Running'" | Select Name,ProcessId

Will show you running processes and their associated process ID. You can then query Win32_Process with the given process ID to see who the process is running as.

But none of that has anything to do with scheduled tasks. Versions of Windows prior to Windows 8 do not provide PowerShell-native mechanisms for working with scheduled tasks. You would need to run Schtasks.exe to get that list. You could also run:

Get-WmiObject Win32_ScheduledJob

The object returned by that command is documented at http://msdn.microsoft.com/en-us/library/aa394399(v=vs.85).aspx. That will show you the owner. However, once a scheduled task is running, there’s no “connection” between the scheduled task definition and the running process. A scheduled task will only show up in the process list (Get-Process, or Task Manager) if the scheduled task is actually RUNNING at that exact moment.

I think your best bet would be to start with

Schtasks /query

As it will show all tasks, whether they are scheduled, and whether they are running. It will NOT show who scheduled them, and it will not show what user account they run under. Unfortunately, in older versions of Windows, it’s difficult to extract that information using automation. That’s why newer versions of Windows are nicer – they’re easier to automate. You can query Win32_ScheduledJob to get some of the information, like who set up the scheduled task in the first place. But that also won’t show you what user the task runs as.


Viewing all articles
Browse latest Browse all 13067

Trending Articles