0% found this document useful (0 votes)
3 views

win-auodeployment_script

The document is a PowerShell script for deploying a website by backing up the existing site, extracting a new build from a zip file, and replacing the old files with the new ones. It includes error handling for the zip file path and ensures unique backup folder creation. Finally, it stops and starts the IIS website and application pool during the deployment process.

Uploaded by

Sagar Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

win-auodeployment_script

The document is a PowerShell script for deploying a website by backing up the existing site, extracting a new build from a zip file, and replacing the old files with the new ones. It includes error handling for the zip file path and ensures unique backup folder creation. Finally, it stops and starts the IIS website and application pool during the deployment process.

Uploaded by

Sagar Kumar
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

# Define variables

$websiteName = "abc.example.info"
$rootFolder = "D:\root-folder-of-website"
$backupFolderBase = "D:\Backups\abc.example.com"
$date = Get-Date -Format "dd-MM-yyyy"
$retryCount = 1

# Prompt for the build zip file


$zipFilePath = Read-Host "Enter the path to the build zip file (e.g., C:\path\to\
build.zip)"

# Check if the zip file exists


if (-not (Test-Path -Path $zipFilePath)) {
Write-Host "The specified zip file does not exist. Please check the path and
try again."
exit
}

# Create a unique backup folder with date and retry count


do {
$backupFolder = "$backupFolderBase\bkp-$date-$retryCount"
$retryCount++
} while (Test-Path -Path $backupFolder)

New-Item -ItemType Directory -Path $backupFolder -Force | Out-Null

# Stop the IIS website and app pool


Import-Module WebAdministration
Stop-WebAppPool -Name $websiteName
Stop-Website -Name $websiteName
Write-Host "Stopped IIS website and application pool: $websiteName"

# Backup the website root folder


Copy-Item -Path "$rootFolder\*" -Destination $backupFolder -Recurse -Force
Write-Host "Backup completed: $backupFolder"

# Extract the zip file to a temporary folder


$tempExtractFolder = "$env:TEMP\build"
Expand-Archive -Path $zipFilePath -DestinationPath $tempExtractFolder -Force
Write-Host "Extracted $zipFilePath to $tempExtractFolder"

# Replace the files in the root folder with the unzipped contents
Remove-Item -Path "$rootFolder\*" -Recurse -Force
Copy-Item -Path "$tempExtractFolder\build\*" -Destination $rootFolder -Recurse -
Force
Write-Host "Replaced files in $rootFolder with contents of the build"

# Clean up temporary folder


Remove-Item -Path $tempExtractFolder -Recurse -Force

# Start the IIS website and app pool


Start-WebAppPool -Name $websiteName
Start-Website -Name $websiteName
Write-Host "Started IIS website and application pool: $websiteName"

Write-Host "Deployment completed successfully."

You might also like