Simplest way to restart service on a remote computer

后端 未结 11 1935
我寻月下人不归
我寻月下人不归 2020-12-23 13:07

What\'s the easiest programmatic way to restart a service on a remote Windows system? Language or method doesn\'t matter as long as it doesn\'t require human interaction.

11条回答
  •  伪装坚强ぢ
    2020-12-23 13:48

    As of Powershell v3, PSsessions allow for any native cmdlet to be run on a remote machine

    $session = New-PSsession -Computername "YourServerName"
    Invoke-Command -Session $Session -ScriptBlock {Restart-Service "YourServiceName"}
    Remove-PSSession $Session
    

    See here for more information

提交回复
热议问题