Restart-RemoteService

Restarts a service on a remote machine.

Syntax

Restart-RemoteService [-Name] <String> [-ComputerName] <String> [-WhatIf] [-Confirm] [<CommonParameters>]

Description

One of the annoying features of PowerShell is that the Stop-Service, Start-Service and Restart-Service cmdlets don't have ComputerName parameters to start/stop/restart a service on a remote computer. You have to use Get-Service to get the remote service:

$service = Get-Service -Name DeathStar -ComputerName Yavin
$service.Stop()
$service.Start()

# or (and no, you can't pipe the service directly to `Restart-Service`)
Get-Service -Name DeathStar -ComputerName Yavin | 
    ForEach-Object { Restart-Service -InputObject $_ }

This function does all this unnecessary work for you.

You'll get an error if you attempt to restart a non-existent service.

Parameters

Name Type Description Required? Pipeline Input Default Value
Name String

The service name to restart.

true false
ComputerName String

The name of the computer where the service lives.

true false
WhatIf SwitchParameter false false
Confirm SwitchParameter false false
CommonParameters This cmdlet supports common parameters. For more information type
Get-Help about_CommonParameters.

EXAMPLE 1

Restart-RemoteService -Name DeathStar -ComputerName Yavin

Restarts the DeathStar service on Yavin. If the DeathStar service doesn't exist, you'll get an error.