Solved

Start Service On a Number of Servers

Posted on 2014-01-26
5
341 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 28

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 28

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 28

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
This article will help you understand what HashTables are and how to use them in PowerShell.
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now