What's equivalent SC command for below powershell script ?
Get-Service -ComputerName localhost -Name Spooler | select machinename,name,starttype,status
Use the qc command to query the service config for the startup type and name:
~> sc.exe qc spooler
SERVICE_NAME: spooler
TYPE : 110 WIN32_OWN_PROCESS (interactive)
START_TYPE : 4 DISABLED
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : C:\WINDOWS\System32\spoolsv.exe
LOAD_ORDER_GROUP : SpoolerGroup
TAG : 0
DISPLAY_NAME : Print Spooler
DEPENDENCIES : RPCSS
: http
SERVICE_START_NAME : LocalSystem
Use the query or queryex commands to fetch the status:
~> sc.exe query spooler
SERVICE_NAME: spooler
TYPE : 110 WIN32_OWN_PROCESS (interactive)
STATE : 1 STOPPED
WIN32_EXIT_CODE : 1077 (0x435)
SERVICE_EXIT_CODE : 0 (0x0)
CHECKPOINT : 0x0
WAIT_HINT : 0x0
sc.exe?Since you tagged only powershell one must assume you're running sc.exe in powershell. I would like to understand why you aren't just using Get-Service? In case you have a real need/valid reason for it, you can try this function.
Function Get-SC {
[cmdletbinding()]
Param(
[parameter(Position=0)]
$Service,
[parameter(Position=1)]
$Computer = 'Localhost'
)
$StartTypeLookup = @{
AUTO_START = 'Automatic'
DEMAND_START = 'Manual'
DISABLED = 'Disabled'
}
switch -Regex (sc.exe \\$computer qc $service){
'DISPLAY_NAME\s+:\s(.+)' {$name = $matches.1}
'START_TYPE[\s\d:]+\s+(\w+)' {$starttype = $StartTypeLookup[$matches.1]}
}
$state = switch -Regex (sc.exe \\$computer query $service){
'STATE\s+.+?(\w+)\s*$' {$matches.1}
}
[PSCustomObject]@{
MachineName = $computer
DisplayName = $name
Name = $Service
StartType = $starttype
Status = $state
}
}
Some testing and results
Example 1
Get-SC WpcMonSvc
MachineName : Localhost
DisplayName : Parental Controls
Name : WpcMonSvc
StartType : Automatic
Status : STOPPED
Example 2
Get-SC -Computer kids1 -Service spooler
MachineName : kids1
DisplayName : Print Spooler
Name : spooler
StartType : Automatic
Status : RUNNING
sc.exe query Spooler,sc.exe queryex Spoolerandsc.exe qc Spooler.