使用Powershell中的InstallUtil安装服务(接受安装参数)

时间:2013-10-16 13:56:04

标签: service powershell-v2.0 installutil

我正在尝试编写一个powershell脚本来安装接受安装参数的服务。

以下在命令提示符

中有效
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"

然而,当我尝试从Powershell运行installutil时,它不起作用并给我一个例外

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?任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:3)

使用Start-Process 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