2013-10-16 41 views
2

我正在嘗試編寫一個powershell腳本來安裝接受安裝參數的服務。使用Powershell中的InstallUtil安裝服務(它接受用於安裝的參數)

在命令提示符下

C:\Windows\Microsoft.NET\Framework\v4.0.30319>installutil.exe /ControllerGroup=Delivery  /username=userl /password=pwd /unattended "C:\DocumentProcessingPlatform\Dpp.Service\bin\Debug\Dpp.Service.exe" 

然而,當我嘗試運行installutil從PowerShell的這是行不通的以下作品,給我一個例外

PowerShell腳本

$sn = " ControllerGroup=$line /username=$Username /password=$Password /unattended ""$ServiceExecutablePath""" 
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe $sn 

Exception occurred while initializing the installation: 
System.ArgumentException: File ControllerGroup=Delivery /username=usr /password=pwd /unattended C:\DocumentProcessingPlatform\Dpp.Service\bin\Debug\Dpp.Service.exe does not exist. If this parameter is used as an installer option, the format must be 
/key=[value].. 

哪有我將參數傳遞給installutil?任何幫助表示讚賞。

+0

工作,你可以嘗試$ SN =」/ContControllerGroup = $線/用戶名= $的用戶名/密碼= $密碼/無人值守 「」 $ ServiceExecutablePath 「」 「。您似乎缺少正斜槓/在第一個鍵(ControllerGroup)前面 –

回答

2

得到它通過使用開始處理cmdlet的

$x="" 

$x = "/ControllerGroup=$controllerGroup」, 「/username=$Username」 , "/password=$Password", "/unattended" , $ServiceExecutablePath 

Start-Process –FilePath C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe –ArgumentList $x –NoNewWindow