Set-Service

Starts, stops, and suspends a service, and changes its properties.

Syntax

Set-Service
   [-Name] <String>
   [-DisplayName <String>]
   [-Description <String>]
   [-StartupType <ServiceStartMode>]
   [-Status <String>]
   [-PassThru]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]
Set-Service
   [-DisplayName <String>]
   [-Description <String>]
   [-StartupType <ServiceStartMode>]
   [-Status <String>]
   [-InputObject <ServiceController>]
   [-PassThru]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

Description

The Set-Service cmdlet changes the properties of a service. This includes the status, description, display name, and start mode. You can use this cmdlet to start, stop, or suspend, or pause, a service. To identify the service, enter its service name or submit a service object, or pipe a service name or service object to Set-Service.

Examples

Example 1: Change a display name

Set-Service -Name "lanmanworkstation" -DisplayName "LanMan Workstation"

This command changes the display name of the lanmanworkstation service to LanMan Workstation. The default is Workstation.

Example 2: Change the startup type of services

Set-Service -Name BITS -StartupType Automatic
Get-Service BITS | Select-Object Name, StartType, Status

Name StartType  Status
---- ---------  ------
BITS      Auto Stopped

These commands get the startup type of the Background Intelligent Transfer Service (BITS) service, set the start mode to automatic, and then display the result of the change.

Example 3: Change the description of a service

Get-CimInstance Win32_Service -Filter 'Name = "BITS"'  | Format-List  Name, Description

Name        : BITS
Description : Transfers files in the background using idle network bandwidth. If the service is
              disabled, then any applications that depend on BITS, such as Windows Update or MSN
              Explorer, will be unable to automatically download programs and other information.

Set-Service -Name BITS -Description "Transfers files in the background using idle network bandwidth."
Get-CimInstance Win32_Service -Filter 'Name = "BITS"'  | Format-List  Name, Description

Name        : BITS
Description : Transfers files in the background using idle network bandwidth.

These commands change the description of the BITS service and then display the result.

These commands use the Get-CimInstance cmdlet to get the Win32_Service object for the service, because the ServiceController object that Get-Service returns does not include the service description.

Example 4: Start a service

Set-Service -Name "winrm" -Status Running -PassThru

This command starts the WinRM service. The command uses the Status parameter to specify the desired status, which is running, and the PassThru parameter to direct Set-Service to return an object that represents the WinRM service.

Example 5: Suspend a service

Get-Service -Name "schedule" | Set-Service -Status paused

This command suspends the Schedule service. It uses Get-Service to get the service. A pipeline operator (|) sends the service to Set-Service, which changes its status to Paused.

Example 6: Stop a service

$s = Get-Service -Name "schedule"
Set-Service -InputObject $s -Status stopped

These commands stop the Schedule service.

The first command uses Get-Service to get the Schedule service. The command stores the service in the $s variable.

The second command changes the status of the Schedule service to Stopped. It uses the InputObject parameter to submit the service stored in the $s variable, and it uses the Status parameter to specify the desired status.

Example 7: Stop a service on a remote system

$Cred = Get-Credential
$s = Get-Service -Name "schedule"
Invoke-Command -ComputerName 'server01.contoso.com' -Credential $Cred -ScriptBlock {
  Set-Service -InputObject $s -Status 'Stopped'
}

These commands stop the Schedule service on a remote system.

For more information see Invoke-Command.

Example 8: Change credential of a service

$credential = Get-Credential
Set-Service -Name "schedule" -Credential $credential

These commands changes credentials of the Schedule service.

The first command uses Get-Credential to get the new credentials. The command stores the credentials in the $credential variable.

The second command changes the credentials of the Schedule service.

Required Parameters

-Name

Specifies the service name of the service to be changed. Wildcard characters are not permitted. You can also pipe a service name to Set-Service.

Type:String
Aliases:ServiceName, SN
Position:1
Default value:None
Accept pipeline input:True (ByPropertyName, ByValue)
Accept wildcard characters:False

Optional Parameters

-Confirm

Prompts you for confirmation before running the cmdlet.

Type:SwitchParameter
Aliases:cf
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False
-Credential

Specifies the credentials under which the service should be run.

Type:PSCredential
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Description

Specifies a new description for the service.

The service description appears in Services in Computer Management. Description is not a property of the ServiceController object that Get-Service gets. To see the service description, use Get-CimInstance to get a Win32_Service object that represents the service.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DisplayName

Specifies a new display name for the service.

Type:String
Aliases:DN
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-InputObject

Specifies a ServiceController object that represents the service to change. Enter a variable that contains the object, or type a command or expression that gets the object, such as a Get-Service command. You can also pipe a service object to Set-Service.

Type:ServiceController
Position:Named
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False
-PassThru

Returns objects that represent the services that were changed. By default, this cmdlet does not generate any output.

Type:SwitchParameter
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False
-StartupType

Specifies the start mode of the service. The acceptable values for this parameter are:

  • Automatic. Start when the system starts.
  • Manual. Starts only when started by a user or program.
  • Disabled. Cannot be started.
Type:ServiceStartMode
Aliases:StartMode, SM, ST
Parameter Sets:Boot, System, Automatic, Manual, Disabled
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Status

Specifies the status for the service. The acceptable values for this parameter are:

  • Running. Starts the service.
  • Stopped. Stops the service.
  • Paused. Suspends the service.
Type:String
Parameter Sets:Running, Stopped, Paused
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.

Type:SwitchParameter
Aliases:wi
Position:Named
Default value:False
Accept pipeline input:False
Accept wildcard characters:False

Inputs

System.ServiceProcess.ServiceController, System.String

You can pipe a service object or a string that contains a service name to Set-Service.

Outputs

System.ServiceProcess.ServiceController

This cmdlet does not return any objects.

Notes

Use of Set-Service requires elevated permissions. Start PowerShell by using the Run as administrator option. Set-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.