Skip to content

Instantly share code, notes, and snippets.

@iOnline247
Created November 10, 2022 19:10
Show Gist options
  • Save iOnline247/0a58a6321e4bfc29aa6e42c3f23f9478 to your computer and use it in GitHub Desktop.
Save iOnline247/0a58a6321e4bfc29aa6e42c3f23f9478 to your computer and use it in GitHub Desktop.
P0$H Boilerplate
param(
[ValidateSet("DEV","TEST","PROD")]
[parameter(mandatory=$true)]
[string]$Environment = ("DEV","TEST","PROD")
)
# TODO
# Update with newer code patterns
$path = Split-Path -Path $MyInvocation.MyCommand.Path
$scriptName = [System.IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Source)
$startTime = Get-Date
Start-SPAssignment -global
Start-Transcript -Path "$path\$($scriptName)_$($timestamp.ticks).log" -Force
$hostName = $env:COMPUTERNAME
$Environments = @{
"DEV" = @{
"WebAppUrl" = "https://$($hostName).domain.gov"
"WebSiteUrl" = "https://$($hostName).domain.gov"
"SQLServerName" = "SERVER-NAME"
"SQLInstance" = "SQLExample"
"SQLBackupDir" = "F:\Backups"
"DBName" = "DB_NAME"
}
"TEST" = @{
"WebAppUrl" = "https://WEBAPPLICATION.domain.tld/"
"WebSiteUrl" = "https://app.domain.tld"
"SQLServerName" = "SERVER-NAME"
"SQLInstance" = "SQLExample"
"SQLBackupDir" = "F:\Backups"
"DBName" = "DB_NAME"
}
"PROD" = @{
"WebAppUrl" = "https://webApp.domain.tld"
"WebSiteUrl" = "https://app.domain.tld"
"SQLServerName" = "SERVER-NAME"
"SQLInstance" = "SQLExample"
"SQLBackupDir" = "F:\Backups"
"DBName" = "DB_NAME"
}
}
$WebSiteUrl = $Environments.Get_Item($Environment).WebSiteUrl;
function SPACER() {
Write-Host "`r`n******************************`r`n"
}
Write-Output "Start time: $($timestamp)"
Write-Output "Deploying to $($WebSiteUrl)`r`n"
function Show-Example ($seconds) {
$initalWaitInSeconds = $seconds
$activity = ('Waiting for {0} seconds total' -f $initalWaitInSeconds)
while ($seconds -gt 0) {
$percentage = ([Math]::Floor([Math]::Abs(($seconds/$initalWaitInSeconds)-1)*100))
Write-Progress -Activity $activity -Status ('{0}%' -f $percentage) -PercentComplete $percentage;
Start-Sleep -Seconds 5;
$seconds -= 5
}
}
try {
SPACER
Show-Example -seconds 60
SPACER
} catch [system.exception] {
Write-Output "!!!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!!!"
Write-Output $_.Exception.Message
Write-Output "!!!!!!!!!!!!!!!!! ERROR !!!!!!!!!!!!!!!!!"
} finally {
$endTime = Get-Date
Write-Output "`r`n`r`nEnd time: $endTime"
Write-Output "Total Time Taken: $($endTime - $startTime)"
Stop-Transcript
Stop-SPAssignment -global
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment