![](/img/trans.png)
[英]Powershell script to checking services on multiple remote machines and to start them if they are not running
[英]Remote start services
我嘗試在用戶輸入后遠程啟動服務。
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
可解決問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.