Get startup type of Windows service using PowerShell

后端 未结 10 2370
小蘑菇
小蘑菇 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 20:04

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

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

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

    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.

    0 讨论(0)
提交回复
热议问题