2015-11-05 55 views
2

我使用的功率腳本部署的網站,服務器上運行Windows 7與IIS 7.5
我使用下面的代碼來部署應用程序
$arguments = [string[]]@( "-verb:sync", "-source:package='$PackagePath'", "-dest:auto,computerName='$PublishUrl',AuthType='NTLM'", "-setParam:name='IIS Web Application Name',value='$($WebApp)'", "-allowUntrusted")
Start-Process $msdeploy -ArgumentList $arguments -NoNewWindow -Wait
如何檢查MS部署工作正常

上面的腳本

工作正常。

我要趕負case.When我在機器上禁用Web部署代理服務,它拋出一個消息(電源外殼沒有這當作錯誤或異常)

Error Code: ERROR_COULD_NOT_CONNECT_TO_REMOTESVC
More Information: Could not connect to the remote computer ("localhost") using the specified process ("Web Deployment Agent Service") because the server did not respond. Make sure that the process ("Web Deployment Agent Service") is start ed on the remote computer. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_COULD_NOT_CONNECT_TO_REMO TESVC.
Error: The remote server returned an error: (503) Server Unavailable.
Error count: 1.

我怎樣才能在PowerShell中捕獲這個。

回答

0

試着在你的腳本運行結束這樣的:

if ($Error.Count -gt 0) 
{ 
    $Error | ForEach-Object { Write-Host $_ -ForegroundColor Red } 
    exit -1; 
} 
0

我解決了這個問題,用下面的命令:

$arguments = [string[]]@(
     "-verb:sync", 
     "-source:package='$PackagePath'", 
     "-dest:auto,computerName='$PublishUrl',AuthType='NTLM'", 
     "-setParam:name='IIS Web Application Name',value='$($WebApp)'", 
     "-allowUntrusted") 

    #Restore IIS 
    $proc = Start-Process $msdeploy -ArgumentList $arguments -NoNewWindow -Wait -PassThru 
    $handle = $proc.Handle 
    $proc.WaitForExit(); 

    if ($proc.ExitCode -ne 0) { 
     Write-Warning "$_ exited with status code $($proc.ExitCode)" 
    } 

這裏的祕密是「-PassThru」。檢查出microsoft documentation

相關問題