3

嗨,我有一个 powershell 脚本来从集群管理器停止服务,卸载服务,重新安装服务,然后从集群管理器启动服务。NServiceBus.Host.exe 用于卸载和重新安装服务。我遇到了安装问题。该服务已成功安装,但即使我将“/startManually”作为参数发送,该服务始终是自动启动类型。其次,在安装时,我得到一个 Login failed for user sql 错误,指出 userName 是本地机器名,即使我指定了要使用的服务的用户名和密码。下面是我安装服务的代码行。任何帮助都是一种祝福。

& "NServiceBus.Host.exe" ("/install", "/startManually", "/serviceName:$ServiceName", "/displayName:$ServiceName", "/username:$ServiceUserName", "/password:$ServicePassword") > tmp.txt
4

1 回答 1

1

I generally recommend using the Start-Process cmdlet to launch processes from PowerShell. This makes the whole process (no pun intended) of launching processes much easier to troubleshoot.

You can build your command line arguments into a variable, and pass that resulting variable into the -ArgumentList parameter.

$Arguments = '/install /startManually /serviceName:{0} /displayName:{0} /username:{1} /password:{2}' -f $ServiceName, $ServiceUserName, $ServicePassword)
$nServiceBus = Resolve-Path -Path nServiceBus.Host.exe;

Write-Host -Object ('Argument string is: {0}' -f $Arguments);
Write-Host -Object ('Path to nServiceBus.Host.exe is: {0}' -f $nServiceBus);
Start-Process -Wait -NoNewWindow -FilePath $nServiceBus -ArgumentList $Arguments -RedirectStandardOutput tmp.txt;

Hope this helps.

于 2012-10-14T18:06:20.467 回答