CaussyR
asked on
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","S RV04"
$Services = "McAfeeEngineService","McA feeFramewo rk","McShi eld","McTa skManager"
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], ParameterBindingValidation Exception
+ FullyQualifiedErrorId : ParameterArgumentValidatio nErrorNull NotAllowed ,Microsoft .PowerShel l.Com
mands.SetServiceCommand"
I have attempted to change the $services to [String]$Services but still get the same error.
$Servers = "SRV01","SRV02","SRV03","S
$Services = "McAfeeEngineService","McA
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], ParameterBindingValidation
+ FullyQualifiedErrorId : ParameterArgumentValidatio
mands.SetServiceCommand"
I have attempted to change the $services to [String]$Services but still get the same error.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I updated the previous comment with a working script, that should do what you need.
ASKER
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.
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 {
invoke-command -computername $server -scriptblock {
ASKER
That's perfect, thank you very much....this has saved me from running an MMC to 16 servers !!