You are currently viewing PowerShell Set-Service And New-Service Cmdlets

PowerShell Set-Service And New-Service Cmdlets

PowerShell Set-Service And New-Service Cmdlets

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed Get-Service cmdlet in PowerShell.

https://cloudaffaire.com/powershell-get-service-cmdlet/

In this blog post, we will discuss Set-Service and New-Service cmdlets in PowerShell. You can use Set-Service cmdlet to modify properties of a service such as Status, Description, DisplayName, StartupType, etc. Using Set-Service cmdlet, you can start, stop, suspend, or pause a service in both your local system as well as your remote system. You need permission to manage windows service to use Set-Service cmdlet. Set-Service cmdlet can also be used to manage the service property of a remote computer using ‘ComputerName’ parameter.

You can use New-Service cmdlet to create a new windows service. New-Service cmdlet creates a new windows service in the registry and in the service database. To create a new service, you need to have manage service permission and an executable file for your service. New-Service cmdlet provides different parameters using which you can define service property line service name, service dependencies, service description, service start-up mode, etc.

Set-Service Cmdlet Syntax:

New-Service Cmdlet Syntax:

Set-Service Cmdlet Argument List:

  • ComputerName: Specifies one or more computers. For remote computers, type the NetBIOS name, an IP address, or a fully qualified domain name.
  • Confirm: Prompts you for confirmation before running Set-Service.
  • Description: Specifies a new description for the service.
  • DisplayName: Specifies, as a string array, the display names of services to be modified. Wildcards are permitted.
  • InputObject: Specifies a ServiceController object that represents the service to change.
  • Name: Specifies the service name of the service to be changed. Wildcard characters aren’t permitted.
  • PassThru: Returns a ServiceController object that represents the services that were changed.
  • StartupType: Sets the startup type of the service. The acceptable values for this parameter are:
    • Automatic: The service is started or was started by the operating system, at system start-up.
    • Disabled: The service is disabled and cannot be started by a user or application.
    • Manual: The service is started only manually, by a user, using the Service Control Manager, or by an application.
    • Boot: Indicates that the service is a device driver started by the system loader.
    • System: Indicates that the service is a device driver started by the ‘IOInitSystem()’ function.
  • 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.
  • WhatIf: Shows what would happen if Set-Service runs. The cmdlet isn’t run.

New-Service Cmdlet Argument List:

  • BinaryPathName: Specifies the path of the executable file for the service. This parameter is required.
  • Confirm: Prompts you for confirmation before running the cmdlet.
  • Credential: Specifies the account used by the service as the Service Logon Account.
  • DependsOn: Specifies the names of other services upon which the new service depends.
  • Description: Specifies a description of the service.
  • DisplayName: Specifies a display name for the service.
  • Name: Specifies the name of the service. This parameter is required.
  • StartupType: Sets the startup type of the service. The acceptable values for this parameter are:
    • Automatic: The service is started or was started by the operating system, at system start-up.
    • Disabled: The service is disabled and cannot be started by a user or application.
    • Manual: The service is started only manually, by a user, using the Service Control Manager, or by an application.
    • Boot: Indicates that the service is a device driver started by the system loader.
    • System: Indicates that the service is a device driver started by the ‘IOInitSystem()’ function.
  • WhatIf: Shows what would happen if the cmdlet runs. The cmdlet is not run.

PowerShell Set-Service And New-Service Cmdlet:

Create A New Windows Service In PowerShell:

Change Windows Service Display Name In PowerShell:

Change Windows Service Description In PowerShell:

Change Windows Service Start-Up Mode In PowerShell:

Change Windows Service Status In PowerShell:

Hope you have enjoyed this article. In the next blog post, we will discuss other service-related cmdlets in PowerShell.

To Set more details on PowerShell, kindly follow below official documentation

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about?view=powershell-5.1

 

Leave a Reply