使用PowerShell 2.0在远程计算机上安装Windows服务

时间:2011-01-11 20:31:53

标签: powershell

我想在检测到服务是否存在后使用PowerShell 2.0来安装Windows服务。我有责任检测服务是否有效,但无法使安装正常工作。

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

运行此行会产生此错误:

  

方法调用失败,因为[System.Management.ManagementClass]没有   包含名为'op_Addition'的方法。

1 个答案:

答案 0 :(得分:4)

用括号括起所有字符串:

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

问题是[wmiclass]只是将第一个字符串"\\"转换为[System.Management.ManagementClass],然后尝试将自身添加到字符串中。