Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Remote Service commands – multiple services/servers?

$
0
0

According to its help file, the Name parameter of Set-Service doesn't accept multiple values, so you have to use foreach. I can't test this right now and I don't want to mess with services on my laptop, but that's what I'd try:

$services = Get-Service -Name (Get-Content E:\Powershellscripts\DisableTheseServices.txt)
 
foreach ($service in $services)
{
Stop-Service -Name $service –Force
Set-Service -Name $service -StartupType Disabled -Verbose
}

To remotely do this on multiple computers, you have to use Invoke-Command and its -ComputerName and -ScriptBlock or -FilePath parameters. The FilePath parameter makes it possible to run a local script on remote computers, so you could save it as a script and do that.
However, you may have to define some arguments and I'm not sure how to make it work.
If a foreach one-liner could accomplish the task, you'd just put that into the ScriptBlock parameter.
In either case, you can feed in the remote computer names into the ComputerName parameter with Get-Content or by typing a list of names.


Viewing all articles
Browse latest Browse all 13067

Trending Articles