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:

#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
}
Advertisements

About Nick Xu

Not a DBA anymore
This entry was posted in Powershell. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s