简体   繁体   English

Powershell - 使用参数启动Windows服务

[英]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.

相关问题 Powershell 不会使用 nssm 启动或停止 Windows 服务 - Powershell will not start or stop Windows service with nssm 修改windows服务参数时出现windows powershell错误 - Windows powershell error when modifying windows service parameter 使用Powershell在Azure VM上启动和停止Windows服务 - Start and stop windows service on a Azure VM using powershell 尝试通过Powershell启动Windows服务时出现错误 - Getting error when trying to start windows service through Powershell 无法启动使用powerShell中的Procrun创建的Windows服务 - Fail to start windows service created using Procrun in powerShell 如何在 .net 核心应用程序中使用 powershell 启动 Windows 服务? - How to start a Windows service using powershell in a .net core application? Powershell 脚本使用 S.no 停止和启动 windows 服务 - Powershell script to Stop and start windows Service using S.no 对于 dotnetcore 3.1 Windows 服务如何使用 powershell 脚本 5.1 停止、卸载、安装和启动服务 - For dotnetcore 3.1 Windows service how to stop, uninstall, install and start the service with a powershell script 5.1 如何使用 windows 服务器 2012 中的 Powershell 5 检查 windows 服务的启动类型是“自动”还是“自动延迟” - How to check the start type of a windows service is "auto" or "auto-delayed" using Powershell 5 in windows server 2012 PowerShell启动服务超时 - PowerShell Start-Service Timeout
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM