开发者

Install Windows service on a remote machine using PowerShell 2.0

开发者 https://www.devze.com 2023-02-03 12:50 出处:网络
I wan开发者_运维百科t to use PowerShell 2.0 to install a Windows service after detecting if the service exists. I have the part to detect the service working but can\'t get the install to work.

I wan开发者_运维百科t to use PowerShell 2.0 to install a Windows service after detecting if the service exists. I have the part to detect the service working but can't get the install to work.

$mc = [wmiclass]"\\"+"$ServiceServer\ROOT\CIMV2:Win32_Service"

Running this line produces this error:

Method invocation failed because [System.Management.ManagementClass] doesn't contain a method named 'op_Addition'.


Wrap all of the string in parentheses:

$mc = [wmiclass]("\\"+"$ServiceServer\ROOT\CIMV2:Win32_Service")

The problem is that [wmiclass] is casting just the first string "\\" to [System.Management.ManagementClass] which then is trying to add itself to a string.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号