$Machines = Get-Content -Path ".\Machines.txt" $service="Microsoft Deployment Agent" $credential = Get-Credential foreach($computer in $Machines) { #$result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $credential).stopservice() #$result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $credential).ChangeStartMode("Disabled") $result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $credential).startservice() $result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $credential).ChangeStartMode("Automatic") } # $result = (gwmi win32_service -computername $computer -filter "name='$service'" -Credential $cred).startservice() #Get-Service -Name $Services -ComputerName $Machines -Credential $credential | Set-Service -Status Started -StartupType Automatic
As usual not really my code but plagiarised. Massive apologies to whoever/wherever I got it as I can’t find it again. As usual – this is really for me!
The Get-Service / Set-Service script was the obvious candidate to use but wont take a credential.
Put a list of machines in Machines.txt.
Original that I’ve lost also took a list of services!
Also - this seems to work -
ReplyDelete(Get-service -ComputerName $server -Name 'w3svc').Stop()
(Get-service -ComputerName $server -Name 'w3svc').Start()
Seems to work – didn’t ask for credentials but I’d already established a connection.