Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Parameters are expected in the following order:
- # 1. Path to ms deploy eg. "C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe"
- # 2. Source server name eg. server1.domain.net
- # 3. Path to setParameters.xml which contains 'IIS Web Application Name' override [Comma delimitted]
- # 4. User name eg. domain\username
- # 5. Password eg. ****** (Caveat: not escaped)
- # 6. Destination server name(s) [Comma delimitted] eg. server2.domain.net,server3.domain.net
- param (
- [parameter(Mandatory=$true)] [string]$msdeploy,
- [parameter(Mandatory=$true)] [string]$source,
- [parameter(Mandatory=$true)] [string]$config,
- [parameter(Mandatory=$true)] [string]$username,
- [parameter(Mandatory=$true)] [string]$password,
- [parameter(Mandatory=$true)] [string]$destination
- )
- try
- {
- Write-Host "##teamcity[blockOpened name='Parameters']"
- Write-Host "msdeploy => '$msdeploy'"
- Write-Host "source => '$source'"
- Write-Host "config => '$config'"
- Write-Host "destination => '$destination'"
- Write-Host "##teamcity[blockClosed name='Parameters']"
- $configs = $config.Split(",")
- foreach ($config in $configs)
- {
- $file = New-Object System.IO.FileInfo ($config)
- if (!$file.Exists)
- {
- throw "'$config' not found (Working: '" + (Get-Location) + "')."
- }
- [xml]$xml = Get-Content $file.FullName
- $app = $xml.selectSingleNode("//setParameter[@name='IIS Web Application Name']/@value").Value
- if ([string]::IsNullOrEmpty($app))
- {
- Write-Host $("##teamcity[message text='{0} does not specify IIS Web Application Name']" -f $file)
- continue
- }
- $destination.Split(",") | ForEach {
- $server = $_
- $name = $("Syncing: [{0}|] {1} => {2}" -f $app, $source, $server)
- Write-Host $("##teamcity[blockOpened name='{0}']" -f $name)
- $command = $("`"{0}`" -verb:sync -source:iisApp='{1}',computername={2},userName='{3}',password='{4}',includeAcls='True',AuthType='NTLM' -dest:iisApp='{1}',computername='{5}',username='{3}',password='{4}',includeAcls='True',AuthType='NTLM'" -f $msdeploy, $app, $source, $username, $password, $server)
- cmd.exe /C "`"$command`""
- if ($LastExitCode -ne 0) {
- [System.Environment]::Exit(1)
- }
- Write-Host $("##teamcity[blockClosed name='{0}']" -f $name)
- }
- }
- } Catch {
- Write-Host $("##teamcity[message text='{0}' status='ERROR']" -f $_.Exception.Message.Replace("]", "|]"))
- [System.Environment]::Exit(1)
- }
Add Comment
Please, Sign In to add comment