PowerShell Logo Small

Set-Service



This is the built-in help made by Microsoft for the command 'Set-Service', in PowerShell version 3 - as retrieved from Windows version 'Microsoft Windows Server 2012 Standard' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

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

SYNTAX


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



Search powershellhelp.space

DESCRIPTION


The Set-Service cmdlet changes the properties of a local or remote service, including the status, description, display name, and start mode.
You can use this cmdlet to start, stop, or suspend (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.



<

RELATED LINKS

Online Version: http://go.microsoft.com/fwlink/?LinkID=113399
Get-Service
New-Service
Restart-Service
Resume-Service
Start-Service
Stop-Service
Suspend-Service

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

PS C:\>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 --------------------------

PS C:\>get-wmiobject win32_service -filter "name = 'SysmonLog'"
ExitCode : 0
Name : SysmonLog
ProcessId : 0
StartMode : Manual
State : Stopped
Status : OK
PS C:\>set-service sysmonlog -startuptype automatic
PS C:\>get-wmiobject win32_service -filter "name = 'SysmonLog'"
ExitCode : 0
Name : SysmonLog
ProcessId : 0
StartMode : Auto
State : Stopped
Status : OK
PS C:\>get-wmiobject win32_service | format-table Name, StartMode -auto
Name StartMode
---- ---------
AdtAgent Auto
Alerter Disabled
ALG Manual
AppMgmt Manual
...



These commands get the startup type of the Performance Logs and Alerts (SysmonLog) service, set the start mode to automatic, and then display
the result of the change.

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

The first command uses the Get-WmiObject cmdlet to get the Windows Management Instrumentation (WMI) object that represents the SysmonLog
service. The default output of this command displays the start mode of the service.

The second command uses Set-Service to change the start mode to automatic. Then, the first command is repeated to display the change.

The final command displays the start mode of all services on the computer.








-------------------------- EXAMPLE 3 --------------------------

PS C:\>set-service -name Schedule -computername S1 -description "Configures and schedules tasks."
PS C:\>get-wmiobject win32_service -computername s1 | where-object {$_.Name -eq "Schedule"} | format-list Name, Description



These commands change the description of the Task Scheduler service on the S1 remote computer and then display the result.

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

The first command uses a Set-Service command to change the description. It identifies the service by using the service name of the service,
"Schedule".

The second command uses the Get-WmiObject cmdlet to get an instance of the WMI Win32_Service that represents the Task Scheduler service. The
first element in the command gets all instances of the Win32_service class.

The pipeline operator (|) passes the result to the Where-Object cmdlet, which selects instances with a value of "Schedule" in the Name
property.

Another pipeline operator sends the result to the Format-List cmdlet, which formats the output as a list with only the Name and Description
properties.








-------------------------- EXAMPLE 4 --------------------------

PS C:\>set-service winrm -status Running -passthru -computername Server02



This command starts the WinRM service on the Server02 computer. The command uses the Status parameter to specify the desired status
("running") and the PassThru parameter to direct Set-Service to return an object that represents the WinRM service.








-------------------------- EXAMPLE 5 --------------------------

PS C:\>get-service schedule -computername S1, S2 | set-service -status paused



This command suspends the Schedule service on the S1 and S2 remote computers. It uses the Get-Service cmdlet to get the service. A pipeline
operator (|) sends the service to the Set-Service cmdlet, which changes its status to "Paused".








-------------------------- EXAMPLE 6 --------------------------

PS C:\>$s = get-service schedule
PS C:\>set-service -inputobject $s -status stopped



These commands stop the Schedule service on the local computer.

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

The second command uses the Set-Service cmdlet to change 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.