Skip to content

Instantly share code, notes, and snippets.

@calderhayes
Created February 22, 2017 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calderhayes/f5c3ed7b8ad7c1047902595b32ee5581 to your computer and use it in GitHub Desktop.
Save calderhayes/f5c3ed7b8ad7c1047902595b32ee5581 to your computer and use it in GitHub Desktop.
# Place this script in Documents\deploy\
# Put source code into the deploy source folder
# Run the script with "powershell .\deploy.ps1"
Import-Module WebAdministration
Get-Content ".\config.ini" | foreach-object -begin {$h=@{}} -process { $k = [regex]::split($_,'='); if(($k[0].CompareTo("") -ne 0) -and ($k[0].StartsWith("[") -ne $True)) { $h.Add($k[0], $k[1]) } }
$environment = $h.Get_Item("Environment")
$siteName = $h.Get_Item("SiteName")
$deploySourceDir = $h.Get_Item("DeploySourceDir")
$deployTargetDir = $h.Get_Item("DeployTargetDir")
$webConfigTemplate = $h.Get_Item("WebConfigTemplate")
$webConfig = $h.Get_Item("WebConfig")
$licTemplate = $h.Get_Item("LicTemplate")
$lic = $h.Get_Item("Lic")
$pingUrl = $h.Get_Item("PingUrl")
$createdDate = Get-ChildItem $deployCommandFile | select CreationTime
Write-Host ""
Write-Host ""
Write-Host "Deploying to environment: $environment / $siteName deployed at $createdDate"
Write-Host ""
Write-Host "Stopping $siteName"
Stop-Website $siteName
Write-Host ""
Write-Host "Removing target directory files ($deployTargetDir)"
Remove-Item -r "$deployTargetDir\*"
Write-Host
Write-Host "Copying source to target"
Copy-Item "$deploySourceDir\*" -destination $deployTargetDir -recurse
Write-Host ""
Write-Host "Copying $webConfigTemplate to $webConfig"
Copy-Item $webConfigTemplate -destination $webConfig
Write-Host ""
Write-Host "Copying license"
Copy-Item $licTemplate $lic
Write-Host ""
Write-Host "Starting website"
Start-Website $siteName
Write-Host ""
Start-Sleep -s 2
Write-Host "Pinging site (This might take a second)"
try {
Invoke-RestMethod $pingUrl
} catch {
# Dig into the exception to get the Response details.
# Note that value__ is not a typo.
#Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__
#Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription
$statusCode = $_.Exception.Response.StatusCode.value__
if ($statusCode -eq 400) {
Write-Host "NOT FOUND, did it fail?"
throw $_.Exception
}
else {
Write-Host "Should be ok"
}
}
Write-Host ""
Write-Host "Deployment complete"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment