Link to home
Start Free TrialLog in
Avatar of michalek19
michalek19Flag for United States of America

asked on

Powershell script to modify service startup type from Automatic to Manual

Hi

Can some help me to modify a powershell script to change STARTUP Type for some of services from AUTOMATIC to MANUAL ?

This script is for starting service. I need the same script to modify Startup Type.

$serverList  = gc servers.txt
$serviceList = gc services.txt

ForEach ($server in $serverList)
{
    ForEach ($service in $serviceList)
    {
        Get-Service -Name $service -ComputerName $server | Start-service
    }
}
SOLUTION
Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Above answers your question directly, but it's much better to make use of the string array feature of Get-Service.
$serverList  = gc servers.txt
$serviceList = gc services.txt
Get-Service -Name $serviceList -ComputerName $serverList | Set-Service -StartupType Manual # |  Start-Service

Open in new window

or
Get-Service -Name (gc services.txt) -ComputerName (gc servers.txt) | Set-Service -StartupType Manual # |  Start-Service

Open in new window

Qlemo would you be able to explain why its better to do it your method vs Jose.  
Yours look more straight forward, but is there any benefit in performance?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial