< Back

Restart-CRemoteService

Sun Jan 12, 2020 11:02 pm

NAME Restart-CRemoteService



SYNOPSIS

Restarts a service on a remote machine.





SYNTAX

Restart-CRemoteService [-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 <String>

The service name to restart.



Required? true

Position? 1

Default value

Accept pipeline input? false

Accept wildcard characters? false



-ComputerName <String>

The name of the computer where the service lives.



Required? true

Position? 2

Default value

Accept pipeline input? false

Accept wildcard characters? false



-WhatIf [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



-Confirm [<SwitchParameter>]



Required? false

Position? named

Default value

Accept pipeline input? false

Accept wildcard characters? false



<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,

ErrorAction, ErrorVariable, WarningAction, WarningVariable,

OutBuffer, PipelineVariable, and OutVariable. For more information, see

about_CommonParameters (https:/go.microsoft.com/fwlink/?LinkID=113216).



INPUTS



OUTPUTS



-------------------------- EXAMPLE 1 --------------------------



PS C:\\>Restart-CRemoteService -Name DeathStar -ComputerName Yavin



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











RELATED LINKS