Two Ways to Control Services on a Remote Computer in Powershell

I am just making a note here about the two alternatives that I found via Google. The first one is on Hey! Scripting Guy’s blog post and the second one is here. To wrap up, I am summing up the below two functions:

[sourcecode language=”powershell”]
#Function to start a service on remote computer
Function Start-Service2
{
param([String[]]$ComputerName = $env:COMPUTERNAME, [String$ServiceName)
Get-Service -ComputerName $ComputerName -Name $ServiceName | Start-Service
}

#Function to stop a service on remote computer
Function Stop-Service2
{
param([String[]]$ComputerName = $env:COMPUTERNAME, [String]ServiceName)

Get-Service -ComputerName $ComputerName -Name $ServiceName | Stop-Service -force
}
[/sourcecode]


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *