Powershell – Start a Windows service

Powershell has a Start-Service command that can be used to start a Windows service. Here’s a function to check if a service has been stopped, and to start it if it has.

function StartService ([string] $ServiceName) {
$ServicePrior = get-service $ServiceName
if ($ServicePrior.status -eq “Stopped”) {
Start-Service $ServiceName
Write-Host “Started Service ” $ServiceName

Call by:
StartService MSSQL`$SQL2012EVAL

The tick is to escape the dollar sign in the service name.
Stop-Service will stop the service.


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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: