Get startup type of Windows service using PowerShell

后端 未结 10 2369
小蘑菇
小蘑菇 2020-12-23 19:22

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 disp

相关标签:
10条回答
  • 2020-12-23 19:54

    Use:

    Get-Service BITS | Select StartType
    

    Or use:

    (Get-Service -Name BITS).StartType
    

    Then

    Set-Service BITS -StartupType xxx
    

    [PowerShell 5.1]

    0 讨论(0)
  • 2020-12-23 19:58

    It is possible with PowerShell 4.

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

    screenshot

    0 讨论(0)
  • 2020-12-23 20:01

    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.

    0 讨论(0)
  • 2020-12-23 20:01

    You can use also:

    (Get-Service 'winmgmt').StartType
    

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

    0 讨论(0)
  • 2020-12-23 20:02

    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'"
    
    0 讨论(0)
  • 2020-12-23 20:03

    With PowerShell version 4:

    You can run a command as given below:

       Get-Service | select -property name,starttype
    
    0 讨论(0)
提交回复
热议问题