powershell - 远程启动服务
问题描述
我正在尝试在用户输入后远程启动服务。
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"
}
}
它只是返回
无法启动“服务”
几乎像
(Get-WmiObject Win32_Service -Filter -ComputerName $ComputerName "Name='$ServiceName'").StartService()
不起作用。
任何想法为什么它不起作用?
编辑:
来自块的实际错误消息catch
:
缺少参数“过滤器”的参数。指定“System.String”类型的参数,然后重试。
解决方案
(Get-WmiObject Win32_Service -ComputerName $ComputerName -Filter "Name='$ServiceName'").StartService()
搬家-Filter
解决了这个问题。
推荐阅读
- javascript - Angular 10:Styles.css 未加载到 Index.html
- javascript - NodeJs,Canvas UnhandledPromiseRejectionWarning:错误:不支持的图像类型
- reactjs - 一些图像显示在 React Native iOS 模拟器中,而另一些则没有?
- c# - 使用 c# 的 DocuSign 嵌入式签名注销
- python - 创建数学序列
- azure - 如何使用 PowerShell 为 Azure 列表 blob REST API 使用 nextmarker 参数
- r - 循环遍历 R 中的列
- scala - 从 Azure Databricks 中的 azure 存储容器读取文件并修改文件名
- java - 使用 PowerMock 的静态方法的 Junit 失败:org.mockito.exceptions.misusing.MissingMethodInvocationException
- three.js - three.js 如何运行着色器程序