Solved

Start Service On a Number of Servers

Posted on 2014-01-26
5
348 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
[X]
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
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

735 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