If I know a service name, and have enough permission, how do I set a Windows Service to be auto-restart in PowerShell?
I am using PowerShell 1.0, and the OS is Windows Server 2003.
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.
To start or stop a service through PowerShell, you can use the Start-Service or the Stop Service cmdlet, followed by the name of the service that you want to start or stop. For instance, you might enter Stop-Service DHCP or Start-Service DHCP.
To change a service startup behavior, select the General tab, then click in the “Startup type:” list box then choose one of the four available options: Automatic (delayed) – Service start after Windows 10 is completely booted. Automatic – Service will start when Windows 10 starts.
You may be asking for:
Set-Service [service name] -startuptype automatic
See:
> get-help set-service
NAME
Set-Service
SYNOPSIS
Starts, stops, and suspends a service, and changes its properties.
SYNTAX
Set-Service [-StartupType {Automatic | Manual | Disabled}] [-DisplayName <string>] [-PassThru] [-Status <string>] [
-InputObject <ServiceController>] [-Description <string>] [-ComputerName <string[]>] [-confirm] [-whatif] [<CommonP
arameters>]
Set-Service [-Status <string>] [-StartupType {Automatic | Manual | Disabled}] [-Description <string>] [-Name] <stri
ng> [-PassThru] [-DisplayName <string>] [-ComputerName <string[]>] [-confirm] [-whatif] [<CommonParameters>]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With