PowerShell: Set Service Startup Mode

# setServiceStartupMode.ps1

$computernames=@(
    'TESTWINDOWS001',
    'TESTWINDOWS002'
)
$servicename='TrustedInstaller'
$startupType='Automatic'

foreach ($computername in $computernames){
    Set-Service -computername $computername -Name $servicename -StartupType $startupType
    Get-Service -computername $computername -Name $servicename|start-service
}

Get-Service -computername $computernames -Name $servicename

Set Failure Restarts

# Currently, Legacy commands must be used as PowerShell doesn't yet have such function
$servicename='TrustedInstaller'
& sc.exe failure $serviceName reset= 30 actions= restart/300000/restart/300000/""/300000

Leave a Reply

Your email address will not be published. Required fields are marked *