Solved

Start Service On a Number of Servers

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

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

803 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