PowerShell Restart Service (Restart-service), using PowerShell can easily operate Windows system services, such as the implementation of automatic restart services. This article describes how to use PowerShell to restart services, and some related content. PowerShell service in the cmdlet is Restart-service, as the name implies is to stop the service and then start up.
PowerShell Restart Service (Restart-service)
Using PowerShell, you can easily operate Windows system services, such as automatic restart services. This article describes how to use PowerShell to restart services, and some related content.
PowerShell service in the cmdlet is Restart-service, as the name implies is to stop the service and then start up.
Grammatical structure
The detailed syntax structure for Restart-service is as follows:
Copy Code code as follows:
Restart-service [-name] <string[]> [-exclude <string[]>] [-force] [-include <string[]>] [-passthru] [ -CONFIRM] [-whatif] [<commonparameters>]
Restart-service-displayname <string[]> [-exclude <string[]>] [-force] [-include <string[]>] [- PassThru] [-confirm] [-whatif] [<commonparameters>]
Restart-service [-inputobject <servicecontroller[]>] [-exclude <string[]>] [-Force] [-Include <string[ ]>] [-passthru] [-confirm] [-whatif] [<commonparameters>]
The first syntax structure is to give it a service name, and then it can be restarted. You can use wildcard characters to manipulate multiple services at the same time. Wildcard matching results can also be eliminated by-exclude parameters.
The second syntax structure is to give it a display name for a service, and then it can be restarted. You can also use wildcard characters to manipulate multiple services at the same time. Wildcard matching results can also be eliminated by-exclude parameters.
The third syntax structure is to enter one or a set of service objects for it, and then it can be restarted. The input here refers to the pipe input. Multiple objects entered by a pipe can also be excluded by-exclude parameters.
What is the service name and service display name?
Here's an explanation of what the service name and service display name are. The so-called service name is the exact name of the service, this name is very short, such as PolicyAgent. and the service display name is for everyone to easily identify a name, such as "IPsec Policy Agent", is the latter is more understandable than the former?
Restarting a service that has stopped
The Restart-service cmdlet sends a STOP message and a startup message to the Windows service controller for the specified service. If a service has stopped, it will start without notifying you that an error has occurred.
What about the joint service?
If this service is associated with the service, you can use the-force parameter to force the restart of the associated service.
Some examples of restarting services
Copy Code code as follows:
C:\ps>restart-service PolicyAgent
This command restarts the IPsec Policy Agent service on the local computer.
Copy Code code as follows:
C:\ps>restart-service-displayname net*-exclude "Net Logon"
This command restarts services with the display name beginning with "NET", except for the net Logon service.
Copy Code code as follows:
C:\ps>get-service net* | Where-object {$_. Status-eq "Stopped"} | Restart-service
This command starts all network services that are stopped on the computer.
About the use of PowerShell restart service script, small series on the introduction of so many, hope to help everyone.