Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@wilsontayar
Forked from rodolfofadino/deployiisnbl.ps1
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wilsontayar/10115506 to your computer and use it in GitHub Desktop.
Save wilsontayar/10115506 to your computer and use it in GitHub Desktop.
Import-Module NetworkLoadBalancingClusters
$CopyOrigin="C:\inetpub\wwwroot\xxxx"
$TimeOut=5
$Servers = New-Object System.Collections.ArrayList
$Servers.Add(@{Ip="xxx.xxx.xxx";Path="E:\xxxx";Urls=("/","/appx")})
$Servers.Add(@{Ip="xxx.xxx.xxx";Path="F:\xxxx";Urls=("/","/appx")})
$Servers.Add(@{Ip="xxx.xxx.xxx";Path="G:\xxxx";Urls=("/","/appx")})
$Servers.Add(@{Ip="xxx.xxx.xxx";Path="H:\xxxx";Urls=("/","/appx")})
foreach($Server in $Servers)
{
Write-Host "Starting deploy on $Server.Ip"
Write-Host "Stopping NLB cluster..."
Stop-NlbClusterNode -Hostname $Server.Ip
Start-Sleep -Second $TimeOut
Write-Host "Copying files..."
robocopy $CopyOrigin $Server.Path /S /E
Start-Sleep -Second $TimeOut
foreach($Url in $Server.Urls){
$s=$Server.Ip
Write-Host "Warming up (http://"$s$Url")..."
$statusCodeOk = $FALSE
while($statusCodeOk -ne $TRUE) {
$request = [System.Net.WebRequest]::Create("http://$s$Url")
Try{
$resp = $request.GetResponse()
$statusCodeOk = $resp.StatusCode -eq "200"
}
Catch{
Write-Host $_.Exception.Message
$statusCodeOk = $FALSE
}
if($statusCodeOk -ne $TRUE) { Write-Host "Trying again..." }
else { Write-Host "Response OK" }
}
}
Start-Sleep -Second $TimeOut
Write-Host "Starting NLB cluster..."
Start-NlbClusterNode -Hostname $Server.Ip
Write-Host $Server.Ip
Write-Host "Done!"
}
@wilsontayar
Copy link
Author

Added the Import-Module command at the beginning and the english translation for all the status messages. :)

@wilsontayar
Copy link
Author

Now the "Warming up" stage will request the server url until a 200 is received. Useful for heavy/cached services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment