64

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".

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
kubusz
  • 943
  • 3
  • 9
  • 17

11 Answers11

47

With PowerShell version 4:

You can run a command as given below:

   Get-Service | select -property name,starttype
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alan Angulo
  • 502
  • 5
  • 2
  • 3
    This seems to work on v5 only - tested on v4 and v2 and the StartType field doesn't populate – KERR Oct 09 '17 at 03:12
  • This doesn't work either in v5 on a Windows Server 2012 R2. It does work on Windows 10, both locally and querying a remote Windows Server 2012 R2. – curropar Dec 21 '17 at 10:56
  • 1
    Reminder to self: adding `| Select-Object *` will list **all** properties on Windows 10 with PowerShell `PSVersion=5.1.17134.407` – Jeroen Wiert Pluimers Jan 07 '19 at 19:37
  • 2
    The property was added to the underlying class in .NET 4.6.1 -- the version of PowerShell is irrelevant https://learn.microsoft.com/en-us/dotnet/api/system.serviceprocess.servicecontroller.starttype – Jaykul Feb 06 '20 at 05:23
42

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'"
ravikanth
  • 24,922
  • 4
  • 60
  • 60
15

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
LinWinGuy
  • 167
  • 1
  • 2
  • Maybe useful: Set-Service -Name Winmgmt -StartupType Manual -Status running - view http://www.computerperformance.co.uk/powershell/powershell_service_set.htm – Kiquenet Apr 16 '14 at 09:20
11

You can use also:

(Get-Service 'winmgmt').StartType

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

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Marcel Janus
  • 233
  • 4
  • 12
  • 2
    This appears to only work on PS v5. I tested on v2 and v4 but it returns nothing. – KERR Oct 09 '17 at 03:10
9

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.

Roman Kuzmin
  • 40,627
  • 11
  • 95
  • 117
  • 1
    Status as of 2015-10-10: [*This is fixed and will be available in the next Technical Preview of Windows Server 2016.*](https://connect.microsoft.com/PowerShell/feedback/details/424948/i-would-like-to-see-the-property-starttype-added-to-get-services) – StackzOfZtuff Nov 23 '15 at 10:38
5

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Brandy Reid
  • 51
  • 1
  • 1
3

Use:

Get-Service BITS | Select StartType

Or use:

(Get-Service -Name BITS).StartType

Then

Set-Service BITS -StartupType xxx

[PowerShell 5.1]

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Dana
  • 71
  • 1
  • 4
1

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
DannyBoy
  • 11
  • 1
1

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
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
emekm
  • 742
  • 5
  • 9
1

It is possible with PowerShell 4.

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

screenshot

0

By default StartType is not shown by Get-Service, but you can always explicitly ask for it:

Get-Service | select StartType,DisplayName | sort StartType,DisplayName

Use Get-Service | Get-Member to see all available fields.

Konstantin Glukhov
  • 1,898
  • 3
  • 18
  • 25