Powershell - 使用参数启动Windows服务

Ben*_*wer 3 powershell windows-services

我需要通过Powershell以'1'作为参数启动Windows服务,如下所示:

在此输入图像描述

所以基本上我想用powershell做这样的事情:

Start-Service _MyService 1 <- won't work
Run Code Online (Sandbox Code Playgroud)

谷歌搜索没有引起任何关注,也许我正在寻找错误的东西,但我不敢相信这是不可能的.有线索吗?

Tun*_*ung 10

另一种方法是使用Get-Service cmdlet获取服务控制器,然后调用其Start()方法.

# "ServiceName" != "Display Name"
$yourService = Get-Service "ServiceName" 
$yourService.Start(1)
Run Code Online (Sandbox Code Playgroud)

  • 为了提供参数列表,我必须在`Start`调用中使用显式数组语法:`$ yourService.Start(@('arg1','arg2'))` (3认同)