次の方法で共有


Set-Service

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

構文

Name (既定)

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

InputObject

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

説明

The Set-Service cmdlet changes the properties of a service such as the Status, Description, DisplayName, and StartupType. Set-Service can start, stop, suspend, or pause a service. To identify a service, enter its service name or submit a service object. Or, send a service name or service object down the pipeline to Set-Service.

Example 1: Change a display name

In this example, a service's display name is changed. To view the original display name, use Get-Service.

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

Set-Service uses the Name parameter to specify the service's name, LanmanWorkstation. The DisplayName parameter specifies the new display name, LanMan Workstation.

Example 2: Change the startup type of services

This example shows how to change a service's startup type.

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

Set-Service uses the Name parameter to specify the service's name, BITS. The StartupType parameter sets the service to Automatic.

Get-Service uses the Name parameter to specify the BITS service and sends the object down the pipeline. Select-Object uses the Property parameter to display the BITS service's status.

Example 3: Change the description of a service

This example changes the BITS service's description and displays the result.

The Get-CimInstance cmdlet is used because it returns a Win32_Service object that includes the service's Description.

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.

Get-CimInstance sends the object down the pipeline to Format-List and displays the service's name and description. For comparison purposes, the command is run before and after the description is updated.

Set-Service uses the Name parameter to specify the BITS service. The Description parameter specifies the updated text for the services' description.

Example 4: Start a service

In this example, a service is started.

Set-Service -Name WinRM -Status Running -PassThru
Status   Name               DisplayName
------   ----               -----------
Running  WinRM              Windows Remote Management (WS-Manag...

Set-Service uses the Name parameter to specify the service, WinRM. The Status parameter uses the value Running to start the service. The PassThru parameter outputs a ServiceController object that displays the results.

Example 5: Suspend a service

This example uses the pipeline to pause to service.

Get-Service -Name Schedule | Set-Service -Status Paused

Get-Service uses the Name parameter to specify the Schedule service, and sends the object down the pipeline. Set-Service uses the Status parameter to set the service to Paused.

Example 6: Stop a service

This example uses a variable to stop a service.

$S = Get-Service -Name Schedule
Set-Service -InputObject $S -Status Stopped

Get-Service uses the Name parameter to specify the service, Schedule. The object is stored in the variable, $S. Set-Service uses the InputObject parameter and specifies the object stored $S. The Status parameter sets the service to Stopped.

パラメーター

-ComputerName

Specifies one or more computers. For remote computers, type the NetBIOS name, an IP address, or a fully qualified domain name. If the ComputerName parameter isn't specified, the command runs on the local computer.

This parameter doesn't rely on PowerShell remoting. You can use the ComputerName parameter even if your computer isn't configured to run remote commands.

パラメーターのプロパティ

型:

String[]

規定値:Local computer
ワイルドカードのサポート:False
DontShow:False
Aliases:cn

パラメーター セット

(All)
配置:Named
必須:False
パイプラインからの値:False
プロパティ名別のパイプラインからの値:True
残りの引数からの値:False

-Confirm

Prompts you for confirmation before running Set-Service.

パラメーターのプロパティ

型:SwitchParameter
規定値:False
ワイルドカードのサポート:False
DontShow:False
Aliases:cf

パラメーター セット

(All)
配置:Named
必須:False
パイプラインからの値:False
プロパティ名別のパイプラインからの値:False
残りの引数からの値:False

-Description

Specifies a new description for the service.

The service description appears in Computer Management, Services. The Description isn't a property of the Get-Service ServiceController object. To see the service description, use Get-CimInstance that returns a Win32_Service object that represents the service.

パラメーターのプロパティ

型:String
規定値:None
ワイルドカードのサポート:False
DontShow:False

パラメーター セット

(All)
配置:Named
必須:False
パイプラインからの値:False
プロパティ名別のパイプラインからの値:False
残りの引数からの値:False

-DisplayName

Specifies a new display name for the service.

パラメーターのプロパティ

型:String
規定値:None
ワイルドカードのサポート:False
DontShow:False
Aliases:DN

パラメーター セット

(All)
配置:Named
必須:False
パイプラインからの値:False
プロパティ名別のパイプラインからの値:False
残りの引数からの値: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 use the pipeline to send a service object to Set-Service.

パラメーターのプロパティ

型:ServiceController
規定値:None
ワイルドカードのサポート:False
DontShow:False

パラメーター セット

InputObject
配置:Named
必須:False
パイプラインからの値:True
プロパティ名別のパイプラインからの値:False
残りの引数からの値:False

-Name

Specifies the service name of the service to be changed. Wildcard characters aren't permitted. You can use the pipeline to send a service name to Set-Service.

パラメーターのプロパティ

型:String
規定値:None
ワイルドカードのサポート:False
DontShow:False
Aliases:ServiceName, SN

パラメーター セット

Name
配置:0
必須:True
パイプラインからの値:True
プロパティ名別のパイプラインからの値:True
残りの引数からの値:False

-PassThru

Returns a ServiceController object that represents the services that were changed. By default, Set-Service doesn't generate any output.

パラメーターのプロパティ

型:SwitchParameter
規定値:False
ワイルドカードのサポート:False
DontShow:False

パラメーター セット

(All)
配置:Named
必須:False
パイプラインからの値:False
プロパティ名別のパイプラインからの値:False
残りの引数からの値:False

-StartupType

Specifies the start mode of the service.

The acceptable values for this parameter are as follows:

  • Automatic. Starts when the system starts.
  • Disabled. Service can't be started.
  • Manual. Starts only when started by a user or program.

パラメーターのプロパティ

型:ServiceStartMode
規定値:None
指定可能な値:Automatic, Boot, Disabled, Manual, System
ワイルドカードのサポート:False
DontShow:False
Aliases:StartMode, SM, ST

パラメーター セット

(All)
配置:Named
必須:False
パイプラインからの値:False
プロパティ名別のパイプラインからの値:False
残りの引数からの値:False

-Status

Specifies the status for the service.

The acceptable values for this parameter are as follows:

  • Paused. Suspends the service.
  • Running. Starts the service.
  • Stopped. Stops the service.

パラメーターのプロパティ

型:String
規定値:None
指定可能な値:Paused, Running, Stopped
ワイルドカードのサポート:False
DontShow:False

パラメーター セット

(All)
配置:Named
必須:False
パイプラインからの値:False
プロパティ名別のパイプラインからの値:False
残りの引数からの値:False

-WhatIf

Shows what would happen if Set-Service runs. The cmdlet isn't run.

パラメーターのプロパティ

型:SwitchParameter
規定値:False
ワイルドカードのサポート:False
DontShow:False
Aliases:wi

パラメーター セット

(All)
配置:Named
必須:False
パイプラインからの値:False
プロパティ名別のパイプラインからの値:False
残りの引数からの値:False

CommonParameters

This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.

入力

System.ServiceProcess.ServiceController, System.String

You can use the pipeline to send a service object or a string that contains a service name to Set-Service.

出力

ServiceController

By default, Set-Service doesn't return any objects. Use the PassThru parameter to output a ServiceController object.

メモ

Set-Service requires elevated permissions. Use the Run as administrator option.

Set-Service can only control services when the current user has permissions to manage services. If a command doesn't work correctly, you might not have the required permissions.

To find a service's service name or display name, use Get-Service. The service names are in the Name column and the display names are in the DisplayName column.