Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Start Service On a Number of Servers

Posted on 2014-01-26
5
347 Views
Last Modified: 2014-01-26
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.
0
Comment
Question by:CaussyR
  • 3
  • 2
5 Comments
 
LVL 29

Accepted Solution

by:
becraig earned 500 total points
ID: 39810532
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

0
 
LVL 29

Expert Comment

by:becraig
ID: 39810579
I updated the previous comment with a working script, that should do what you need.
0
 

Author Comment

by:CaussyR
ID: 39810746
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.
0
 
LVL 29

Expert Comment

by:becraig
ID: 39810748
Ensure there is no carriage return after scriptblock
invoke-command -computername $server -scriptblock {
0
 

Author Closing Comment

by:CaussyR
ID: 39810757
That's perfect, thank you very much....this has saved me from running an MMC to 16 servers !!
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
When you try to extract and to view the contents of a Microsoft Update Standalone Package (MSU) for Windows Vista, you cannot extract the files from the MSU. Here we are going to explain how to extract those hotfix details without using any third pa…
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question