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:
Missing an argument for parameter 'Filter'. Specify a parameter of type 'System.String' and try again.