[英]Powershell - Start Windows service with a parameter
I need to start a windows service via Powershell with a '1' as a parameter, like below: 我需要通过Powershell以'1'作为参数启动Windows服务,如下所示:
So basically I want to do something like this with powershell: 所以基本上我想用powershell做这样的事情:
Start-Service _MyService 1 <- won't work
Googling has produced nothing of note on this, perhaps I'm looking for the wrong thing, but I can't believe it's not possible. 谷歌搜索没有引起任何关注,也许我正在寻找错误的东西,但我不敢相信这是不可能的。 Clues anyone? 有线索吗?
An alternative is to use the Get-Service cmdlet to obtain a service controller, and then invoke its Start() method. 另一种方法是使用Get-Service cmdlet获取服务控制器,然后调用其Start()方法。
# "ServiceName" != "Display Name"
$yourService = Get-Service "ServiceName"
$yourService.Start(1)
If you need to supply multiple arguments (credit to @Mark): 如果你需要提供多个参数(归功于@Mark):
$yourService.Start(@('arg1','arg2'))
您可以调用允许使用参数启动服务的sc.exe:
Invoke-Expression "sc.exe start _MyService 1"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.