Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get startup type of Windows service using PowerShell

How can I get the Windows service startup type using PowerShell and not using WMI?

I looked inside the Get-Service command, and it does not provide something to display the "startup type".

like image 961
kubusz Avatar asked Nov 29 '10 14:11

kubusz


People also ask

What is the startup type of the service?

Services snap-in Acceptable startup types include: Automatic: The service starts at system logon. Automatic (Delayed): The service starts a short while after the system has finished starting up.

How do I view Windows services in PowerShell?

To find the service name and display name of each service on your system, type Get-Service . The service names appear in the Name column, and the display names appear in the DisplayName column. When you sort in ascending order by status value, Stopped services appear before Running services.

What is $_ in PowerShell?

The “$_” is said to be the pipeline variable in PowerShell. The “$_” variable is an alias to PowerShell's automatic variable named “$PSItem“. It has multiple use cases such as filtering an item or referring to any specific object.

How do I get remote computer services in PowerShell?

Getting Remote Services With Windows PowerShell, you can use the ComputerName parameter of the Get-Service cmdlet to get the services on remote computers. The ComputerName parameter accepts multiple values and wildcard characters, so you can get the services on multiple computers with a single command.


10 Answers

WMI is the way to do this.

Get-WmiObject -Query "Select StartMode From Win32_Service Where Name='winmgmt'"

Or

Get-WmiObject -Class Win32_Service -Property StartMode -Filter "Name='Winmgmt'"
like image 98
ravikanth Avatar answered Oct 04 '22 09:10

ravikanth


With PowerShell version 4:

You can run a command as given below:

   Get-Service | select -property name,starttype
like image 32
Alan Angulo Avatar answered Oct 04 '22 08:10

Alan Angulo


In PowerShell you can use the command Set-Service:

Set-Service -Name Winmgmt -StartupType Manual

I haven't found a PowerShell command to view the startup type though. One would assume that the command Get-Service would provide that, but it doesn't seem to.

like image 36
LinWinGuy Avatar answered Oct 04 '22 09:10

LinWinGuy


You can use also:

(Get-Service 'winmgmt').StartType

It returns just the startup type, for example, disabled.

like image 42
Marcel Janus Avatar answered Oct 04 '22 08:10

Marcel Janus


As far as I know there is no “native” PowerShell way of getting this information. And perhaps it is rather the .NET limitation than PowerShell.

Here is the suggestion to add this functionality to the version next:

https://connect.microsoft.com/PowerShell/feedback/details/424948/i-would-like-to-see-the-property-starttype-added-to-get-services

The WMI workaround is also there, just in case. I use this WMI solution for my tasks and it works.

like image 24
Roman Kuzmin Avatar answered Oct 04 '22 07:10

Roman Kuzmin


Once you've upgraded to PowerShell version 5 you can get the startup type.

To check the version of PowerShell you're running, use $PSVersionTable.

The examples below are for the Windows Firewall Service:

For the local system

Get-Service | Select-Object -Property Name,Status,StartType | where-object {$_.Name -eq "MpsSvc"} | Format-Table -auto

For one remote system

Get-Service -ComputerName HOSTNAME_OF_SYSTEM | Select-Object -Property MachineName,Name,Status,StartType | where-object {$_.Name -eq "MpsSvc"} | Format-Table -auto

For multiple systems (must create the systems.txt)

Get-Service -ComputerName (Get-content c:\systems.txt) | Select-Object -Property MachineName,Name,Status,StartType | where-object {$_.Name -eq "MpsSvc"} | Format-Table -auto
like image 42
Brandy Reid Avatar answered Oct 04 '22 09:10

Brandy Reid


Use:

Get-Service BITS | Select StartType

Or use:

(Get-Service -Name BITS).StartType

Then

Set-Service BITS -StartupType xxx

[PowerShell 5.1]

like image 23
Dana Avatar answered Oct 04 '22 09:10

Dana


If you update to PowerShell 5 you can query all of the services on the machine and display Name and StartType and sort it by StartType for easy viewing:

Get-Service |Select-Object -Property Name,StartType |Sort-Object -Property StartType
like image 45
DannyBoy Avatar answered Oct 04 '22 09:10

DannyBoy


You can also use the sc tool to set it.

You can also call it from PowerShell and add additional checks if needed. The advantage of this tool vs. PowerShell is that the sc tool can also set the start type to auto delayed.

# Get Service status
$Service = "Wecsvc"
sc.exe qc $Service

# Set Service status
$Service = "Wecsvc"
sc.exe config $Service start= delayed-auto
like image 21
emekm Avatar answered Oct 04 '22 08:10

emekm


It is possible with PowerShell 4.

Get-Service *spool* | select name,starttype | ft -AutoSize

screenshot

like image 42
user12700803 Avatar answered Oct 04 '22 09:10

user12700803