• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 360
  • Last Modified:

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

I have attempted to change the $services to [String]$Services but still get the same error.
  • 3
  • 2
1 Solution
Ok here is a tested script, should work:

$Servers = ("SRV01","SRV02","SRV03","SRV04")
$Services = ("McAfeeEngineService","McAfeeFramework","McShield","McTaskManager")
foreach ($server in $servers) 
invoke-command -computername $server -scriptblock 
param ($services) 
foreach ($service in $services)
{Set-Service -name $Service -StartupType Disabled -PassThru | Stop-Service -PassThru} 
 } -Argumentlist (,$services)

Open in new window

I updated the previous comment with a working script, that should do what you need.
CaussyRAuthor Commented:
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 {
CaussyRAuthor Commented:
That's perfect, thank you very much....this has saved me from running an MMC to 16 servers !!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now