English 中文(简体)
Checking only "Automatic" services with powershell
原标题:

I ve seen lots of scripts out there for manually stopping/starting services in a list, but how can I generate that list programatically of -just- the automatic services. I want to script some reboots, and am looking for a way to verify that everything did in fact start up correctly for any services that were supposed to.

最佳回答

Get-Service returns System.ServiceProcess.ServiceController objects that do not expose this information. Thus, you should use WMI for this kind of task: Get-WmiObject Win32_Service. Example that shows the required StartMode and formats the output a la Windows control panel:

Get-WmiObject Win32_Service |
Format-Table -AutoSize @(
     Name 
     DisplayName 
    @{ Expression =  State ; Width = 9 }
    @{ Expression =  StartMode ; Width = 9 }
     StartName 
)

You are interested in services that are automatic but not running:

# get Auto that not Running:
Get-WmiObject Win32_Service |
Where-Object { $_.StartMode -eq  Auto  -and $_.State -ne  Running  } |
# process them; in this example we just show them:
Format-Table -AutoSize @(
     Name 
     DisplayName 
    @{ Expression =  State ; Width = 9 }
    @{ Expression =  StartMode ; Width = 9 }
     StartName 
)
问题回答

暂无回答




相关问题
Restart Mac OS X ungracefully using a C++ call?

How do I restart Mac OS X using C++ (not Objetive-C) without invoking any child processes? Don t care if it s ungraceful. system("reboot"); //Is not acceptable as it relies on invoking a process

.Net Remoting - Reboot Server and get reboot status

I have a client server set up between different computers on a network using .Net Remoting in C#. The server runs in a service that starts up when the computer turns on. I want the client to be able ...

Android: popup to reboot phone

I would like to produce a popup window giving the user to ability to select yes to reboot the phone. Possible?

Checking only "Automatic" services with powershell

I ve seen lots of scripts out there for manually stopping/starting services in a list, but how can I generate that list programatically of -just- the automatic services. I want to script some reboots, ...

Restart remote target machine with gdb

I m debugging a Mac OS X kernel via a remote target (target remote-kdp) when it gets into a kernel panic. I can introspect the state of the machine at the time, but if I need to restart the machine I ...

How can I get the Windows last reboot reason

I d like to know what is the Windows API function (if any exists) that provides information about the last Windows reboot source. There are three main possible causes: The computer crashed on a blue ...

Notification when laptop is switch on (boot)

I need to know, is that possible to get a notification through email whenever my laptop is switched on or is connected to internet ? An alternative is to get notification when set service Starts on ...

热门标签