powershellscripts.com

Tutorials  PowerShell Cmdlet Help for Set-Service



NAME
Set-Service

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

SYNTAX
Set-Service [-Name] [-Description ] [-DisplayName ] [-PassThru] [-StartupType {Automatic |
Manual | Disabled}] [-Status ] [-ComputerName ] [-Confirm] [-WhatIf] []

Set-Service [-Description ] [-DisplayName ] [-InputObject ] [-PassThru] [-Startu
pType {Automatic | Manual | Disabled}] [-Status ] [-ComputerName ] [-Confirm] [-WhatIf] [ arameters>]


DESCRIPTION
The Set-Service cmdlet changes the properties of a local or remote service, including the status, description, disp
lay name, and start mode. You can use this cmdlet to start, stop, or suspend (pause) a service. To identify the ser
vice, enter its service name or submit a service object, or pipe a service name or service object to Set-Service.


PARAMETERS
-ComputerName
Specifies one or more computers. The default is the local computer.

Type the NetBIOS name, an IP address, or a fully qualified domain name of a remote computer. To specify the loc
al computer, type the computer name, a dot (.), or "localhost".

This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter of Set-Serv
ice even if your computer is not configured to run remote commands.

Required? false
Position? named
Default value local computer
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 Servic
eController object that Get-Service gets. To see the service description, use Get-WmiObject to get a Win32_Serv
ice object that represents the service.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-DisplayName
Specifies a new display name for the service.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-InputObject
Specifies a ServiceController object that represents the service to be changed. 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 p
ipe a service object to Set-Service.

Required? false
Position? named
Default value
Accept pipeline input? true (ByValue)
Accept wildcard characters? false

-Name
Specifies the service name of the service to be changed. Wildcards are not permitted. You can also pipe a serv
ice name to Set-Service.

Required? true
Position? 1
Default value
Accept pipeline input? true (ByValue, ByPropertyName)
Accept wildcard characters? false

-PassThru []
Returns objects that represent the services that were changed. By default, this cmdlet does not generate any ou
tput.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-StartupType
Changes the start mode of the service. Valid values for StartupType are:

-- Automatic: Start when the system starts.
-- Manual: Starts only when started by a user or program.
-- Disabled: Cannot be started.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Status
Starts, stops, or suspends (pauses) the services. Valid values are:

-- Running: Starts the service.
-- Stopped: Stops the service.
-- Paused: Suspends the service.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-Confirm []
Prompts you for confirmation before executing the command.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false

-WhatIf []
Describes what would happen if you executed the command without actually executing the command.

Required? false
Position? named
Default value
Accept pipeline input? false
Accept wildcard characters? false


This cmdlet supports the common parameters: Verbose, Debug,
ErrorAction, ErrorVariable, WarningAction, WarningVariable,
OutBuffer and OutVariable. For more information, type,
"get-help about_commonparameters".

INPUTS
System.ServiceProcess.ServiceController, System.String
You can pipe a service object or a string that contains a service name to Set-Service.


OUTPUTS
None
This cmdlet does not return any objects.


NOTES


To use Set-Service on Windows Vista and later versions of Windows, start Windows PowerShell with the "Run as ad
ministrator" option.

Set-Service can control services only when the current user has permission to do so. 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 nam
es appear in the Name column and the display names appear in the DisplayName column.


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

C:\PS>set-service -name lanmanworkstation -DisplayName "LanMan Workstation"


Description
-----------
This command changes the display name of the lanmanworkstation service to "LanMan Workstation". (The default is "Wo
rkstation".)





-------------------------- EXAMPLE 2 --------------------------

C:\PS>get-wmiobject win32_service -filter "name = 'SysmonLog'"

ExitCode : 0
Name : SysmonLog
ProcessId : 0
StartMode : Manual
State : Stopped
Status : OK

C:\PS> set-service sysmonlog -startuptype automatic

C:\PS> get-wmiobject win32_service -filter "name = 'SysmonLog'"

ExitCode : 0
Name : SysmonLog
ProcessId : 0
StartMode : Auto
State : Stopped
Status : OK

C:\PS> get-wmiobject win32_service | format-table Name, StartMode -auto

Name StartMode
---- ---------
AdtAgent Auto
Alerter Disabled
ALG Manual
AppMgmt Manual
...


Description
-----------
These commands get the startup type of the Performance Logs and Alerts (SysmonLog) service, set the start mode to a
utomatic, 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 ServiceCon
troller 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 rep
resents 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 d
isplay the change.

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





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

C:\PS>set-service -name Schedule -computername S1 -description "Configures and schedules tasks."

C:\PS> get-wmiobject win32_service -computername s1 | where-object {$_.Name -eq "Schedule"} | format-list Name, Des
cription


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 ServiceCon
troller 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 ser
vice 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 Ta
sk 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 "Sc
hedule" 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 --------------------------

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


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





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

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


Description
-----------
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 "Pau
sed".





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

C:\PS>$s = get-service schedule

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


Description
-----------
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 t
he InputObject parameter to submit the service stored in the $s variable, and it uses the Status parameter to speci
fy the desired status.






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