2011-01-11 152 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]然後嘗試將自己添加到字符串中。

相關問題