List all services, including only the service names and statuses. Have running services listed before stopped services.
Problem:
When I run:
Get-Service | Select –Property Name,Status | Sort –Property Status
I get Stopped services before Running services. Remember that Sort in Powershell is the same as that in other places, ascending by default. Running should be before Stopped, right?
Reason:
I dig into the status property ServiceController.Status Property and
ServiceControllerStatus Enumeration, and find the table below. The table shows Stopped is 0x00000001,and running is 0x00000004. I suspect the sorting on status is based on these values, rather than based on the literals.
Member name | Description | |
---|---|---|
ContinuePending | The service continue is pending. This corresponds to the Win32 SERVICE_CONTINUE_PENDING constant, which is defined as 0x00000005. | |
Paused | The service is paused. This corresponds to the Win32 SERVICE_PAUSED constant, which is defined as 0x00000007. | |
PausePending | The service pause is pending. This corresponds to the Win32 SERVICE_PAUSE_PENDING constant, which is defined as 0x00000006. | |
Running | The service is running. This corresponds to the Win32 SERVICE_RUNNING constant, which is defined as 0x00000004. | |
StartPending | The service is starting. This corresponds to the Win32 SERVICE_START_PENDING constant, which is defined as 0x00000002. | |
Stopped | The service is not running. This corresponds to the Win32 SERVICE_STOPPED constant, which is defined as 0x00000001. | |
StopPending | The service is stopping. This corresponds to the Win32 SERVICE_STOP_PENDING constant, which is defined as 0x00000003. |