< Back
Restart-Service
Post
NAME Restart-Service
SYNOPSIS
Stops and then starts one or more services.
SYNTAX
Restart-Service [-Confirm] -DisplayName <String[]> [-Exclude <String[]>] [-Force] [-Include <String[]>] [-PassThru] [-WhatIf] [<CommonParameters>]
Restart-Service [-InputObject] <ServiceController[]> [-Confirm] [-Exclude <String[]>] [-Force] [-Include <String[]>] [-PassThru] [-WhatIf]
[<CommonParameters>]
Restart-Service [-Name] <String[]> [-Confirm] [-Exclude <String[]>] [-Force] [-Include <String[]>] [-PassThru] [-WhatIf] [<CommonParameters>]
DESCRIPTION
The Restart-Service cmdlet sends a stop message and then a start message to the Windows Service Controller for a specified service. If a service
was already stopped, it is started without notifying you of an error. You can specify the services by their service names or display names, or you
can use the InputObject parameter to pass an object that represents each service that you want to restart.
PARAMETERS
-Confirm [<SwitchParameter>]
Prompts you for confirmation before running the cmdlet.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-DisplayName <String[]>
Specifies the display names of services to restarted. Wildcard carachters are permitted.
Required? true
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
-Exclude <String[]>
Specifies services that this cmdlet omits. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as
s*. Wildcard characters are permitted.
Required? false
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
-Force [<SwitchParameter>]
Restarts a service that has dependent services.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-Include <String[]>
Specifies services that this cmdlet restarts. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such
as s*. Wildcard characters are permitted.
Required? false
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
-InputObject <ServiceController[]>
Specifies ServiceController objects that represent the services to restart. Enter a variable that contains the objects, or type a command or
expression that gets the objects.
Required? true
Position? 0
Default value None
Accept pipeline input? True (ByValue)
Accept wildcard characters? false
-Name <String[]>
Specifies the service names of the services to restart.
Required? true
Position? 0
Default value None
Accept pipeline input? True (ByPropertyName, ByValue)
Accept wildcard characters? false
-PassThru [<SwitchParameter>]
Returns an object that represents the service. By default, this cmdlet does not generate any output.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-WhatIf [<SwitchParameter>]
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
System.ServiceProcess.ServiceController, System.String
You can pipe a service object or a string that contains a service name to this cmdlet.
OUTPUTS
None, System.ServiceProcess.ServiceController
This cmdlet generates a System.ServiceProcess.ServiceController object that represents the restarted service, if you specify the PassThru
parameter. Otherwise, this cmdlet does not generate any output.
NOTES
Restart-Service * can control services only when the current user has permission to do this. If a command does not work correctly, you might
not have the required permissions. To find the service names and display names of the services on your system, type Get-Service ". The service
names appear in the Name column, and the display names appear in the DisplayName * column.
Example 1: Restart a service on the local computer
PS C:\\>Restart-Service -Name winmgmt
This command restarts the Windows Management Instrumentation service (WinMgmt) on the local computer.
Example 2: Exclude a service
PS C:\\>Restart-Service -DisplayName "net*" -Exclude "net logon"
This command restarts the services that have a display name that starts with Net, except for the Net Logon service.
Example 3: Start all stopped network services
PS C:\\>Get-Service -Name "net*" | Where-Object {$_.Status -eq "Stopped"} | Restart-Service
This command starts all of the stopped network services on the computer.
This command uses the Get-Service cmdlet to get objects that represent the services whose service name starts with net. The pipeline operator (|)
sends the services object to the Where-Object cmdlet, which selects only the services that have a status of stopped. Another pipeline operator
sends the selected services to Restart-Service .
In practice, you would use the WhatIf parameter to determine the effect of the command before you run it.
RELATED LINKS
Online Version: http://go.microsoft.com/fwlink/?LinkId=821629
Get-Service
New-Service
Resume-Service
Set-Service
Restart-Service
Stop-Service
Suspend-Service
SYNOPSIS
Stops and then starts one or more services.
SYNTAX
Restart-Service [-Confirm] -DisplayName <String[]> [-Exclude <String[]>] [-Force] [-Include <String[]>] [-PassThru] [-WhatIf] [<CommonParameters>]
Restart-Service [-InputObject] <ServiceController[]> [-Confirm] [-Exclude <String[]>] [-Force] [-Include <String[]>] [-PassThru] [-WhatIf]
[<CommonParameters>]
Restart-Service [-Name] <String[]> [-Confirm] [-Exclude <String[]>] [-Force] [-Include <String[]>] [-PassThru] [-WhatIf] [<CommonParameters>]
DESCRIPTION
The Restart-Service cmdlet sends a stop message and then a start message to the Windows Service Controller for a specified service. If a service
was already stopped, it is started without notifying you of an error. You can specify the services by their service names or display names, or you
can use the InputObject parameter to pass an object that represents each service that you want to restart.
PARAMETERS
-Confirm [<SwitchParameter>]
Prompts you for confirmation before running the cmdlet.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-DisplayName <String[]>
Specifies the display names of services to restarted. Wildcard carachters are permitted.
Required? true
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
-Exclude <String[]>
Specifies services that this cmdlet omits. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such as
s*. Wildcard characters are permitted.
Required? false
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
-Force [<SwitchParameter>]
Restarts a service that has dependent services.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-Include <String[]>
Specifies services that this cmdlet restarts. The value of this parameter qualifies the Name parameter. Enter a name element or pattern, such
as s*. Wildcard characters are permitted.
Required? false
Position? named
Default value None
Accept pipeline input? False
Accept wildcard characters? false
-InputObject <ServiceController[]>
Specifies ServiceController objects that represent the services to restart. Enter a variable that contains the objects, or type a command or
expression that gets the objects.
Required? true
Position? 0
Default value None
Accept pipeline input? True (ByValue)
Accept wildcard characters? false
-Name <String[]>
Specifies the service names of the services to restart.
Required? true
Position? 0
Default value None
Accept pipeline input? True (ByPropertyName, ByValue)
Accept wildcard characters? false
-PassThru [<SwitchParameter>]
Returns an object that represents the service. By default, this cmdlet does not generate any output.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
-WhatIf [<SwitchParameter>]
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Required? false
Position? named
Default value False
Accept pipeline input? False
Accept wildcard characters? false
<CommonParameters>
This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer, PipelineVariable, and OutVariable. For more information, see
about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
INPUTS
System.ServiceProcess.ServiceController, System.String
You can pipe a service object or a string that contains a service name to this cmdlet.
OUTPUTS
None, System.ServiceProcess.ServiceController
This cmdlet generates a System.ServiceProcess.ServiceController object that represents the restarted service, if you specify the PassThru
parameter. Otherwise, this cmdlet does not generate any output.
NOTES
Restart-Service * can control services only when the current user has permission to do this. If a command does not work correctly, you might
not have the required permissions. To find the service names and display names of the services on your system, type Get-Service ". The service
names appear in the Name column, and the display names appear in the DisplayName * column.
Example 1: Restart a service on the local computer
PS C:\\>Restart-Service -Name winmgmt
This command restarts the Windows Management Instrumentation service (WinMgmt) on the local computer.
Example 2: Exclude a service
PS C:\\>Restart-Service -DisplayName "net*" -Exclude "net logon"
This command restarts the services that have a display name that starts with Net, except for the Net Logon service.
Example 3: Start all stopped network services
PS C:\\>Get-Service -Name "net*" | Where-Object {$_.Status -eq "Stopped"} | Restart-Service
This command starts all of the stopped network services on the computer.
This command uses the Get-Service cmdlet to get objects that represent the services whose service name starts with net. The pipeline operator (|)
sends the services object to the Where-Object cmdlet, which selects only the services that have a status of stopped. Another pipeline operator
sends the selected services to Restart-Service .
In practice, you would use the WhatIf parameter to determine the effect of the command before you run it.
RELATED LINKS
Online Version: http://go.microsoft.com/fwlink/?LinkId=821629
Get-Service
New-Service
Resume-Service
Set-Service
Restart-Service
Stop-Service
Suspend-Service