2011-01-11 149 views
2

我想在检测服务是否存在后使用PowerShell 2.0安装Windows服务。我有部分检测服务工作,但无法使安装工作。使用PowerShell 2.0在远程计算机上安装Windows服务

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

运行该生产线生产此错误:

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

+0

如果我只是硬编码的服务器名称似乎工作。任何想法为什么? – Kenoyer130 2011-01-11 20:54:20

回答

4

包装所有括号中的字符串:

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

的问题是,[wmiclass]只是第一串"\\"铸造[System.Management.ManagementClass]然后尝试将自己添加到字符串中。

相关问题