[英]Remote start services
I am trying to start a service remotely after user input. 我尝试在用户输入后远程启动服务。
function Start_Service {
$ComputerName = $txb_hostname.Text
[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
$title = 'Start Service'
$msg = 'Enter Service Name (e.g. AppVClient):'
$ServiceName = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
try {
(Get-WmiObject Win32_Service -ComputerName $ComputerName -filter "Name='$ServiceName'").StartService()
LogWrite "$ServiceName started."
} catch {
LogWrite "Unable to stop $ServiceName"
}
}
It just returns 它只是返回
unable to start "service"
无法启动“服务”
almost like the 几乎像
(Get-WmiObject Win32_Service -Filter -ComputerName $ComputerName "Name='$ServiceName'").StartService()
doesn't work. 不起作用。
Any ideas why it isn't working? 任何想法为什么它不起作用?
Edit: 编辑:
Actual error message from the catch
block: 来自
catch
块的实际错误消息:
Missing an argument for parameter 'Filter'.
缺少参数“过滤器”的参数。 Specify a parameter of type 'System.String' and try again.
指定类型为'System.String'的参数,然后重试。
(Get-WmiObject Win32_Service -ComputerName $ComputerName -Filter "Name='$ServiceName'").StartService()
移动-Filter
可解决问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.