Link to home
Start Free TrialLog in
Avatar of CaussyR
CaussyR

asked on

Start Service On a Number of Servers

i am trying to start 4 services that are across 4 servers.  The script is as follows :

$Servers = "SRV01","SRV02","SRV03","SRV04"

$Services = "McAfeeEngineService","McAfeeFramework","McShield","McTaskManager"

Invoke-Command -ComputerName $Servers -ScriptBlock { Set-Service -name $Service -StartupType Disabled -PassThru | Stop-Service -PassThru }


I'm not a PS guru, but when I run it I get the following error: "Cannot bind argument to parameter 'Name' because it is null.
    + CategoryInfo          : InvalidData: (:) [Set-Service], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Com
   mands.SetServiceCommand"

I have attempted to change the $services to [String]$Services but still get the same error.
ASKER CERTIFIED SOLUTION
Avatar of becraig
becraig
Flag of United States of America 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
I updated the previous comment with a working script, that should do what you need.
Avatar of CaussyR
CaussyR

ASKER

Hi BeCraig,

There is an error at : -Argumentlist (,$services)

When I run the script the following is displayed :

unexpected token '-Argumentlist' in expression or statement.
Ensure there is no carriage return after scriptblock
invoke-command -computername $server -scriptblock {
Avatar of CaussyR

ASKER

That's perfect, thank you very much....this has saved me from running an MMC to 16 servers !!