Powershell - 使用参数启动 Windows 服务 [英] Powershell - Start Windows service with a parameter

查看:56
本文介绍了Powershell - 使用参数启动 Windows 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to start a windows service via Powershell with a '1' as a parameter, like below:

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

So basically I want to do something like this with 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?

推荐答案

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

An alternative is to use the Get-Service cmdlet to obtain a service controller, and then invoke its Start() method.

# "ServiceName" != "Display Name"
$yourService = Get-Service "ServiceName" 
$yourService.Start(1)

如果您需要提供多个参数(归功于@Mark):

If you need to supply multiple arguments (credit to @Mark):

$yourService.Start(@('arg1','arg2'))

这篇关于Powershell - 使用参数启动 Windows 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆