azure_arc_sqlsrv_jumpstart/artifacts/PSProfile.ps1 (44 lines of code) (raw):
function Write-Header {
param (
[string]
$title
)
Write-Host
Write-Host ("#" * ($title.Length + 8))
Write-Host "# - $title"
Write-Host ("#" * ($title.Length + 8))
Write-Host
}
function exec
{
param
(
[ScriptBlock] $ScriptBlock,
[string] $StderrPrefix = "",
[int[]] $AllowedExitCodes = @(0)
)
$backupErrorActionPreference = $script:ErrorActionPreference
$script:ErrorActionPreference = "Continue"
try
{
& $ScriptBlock 2>&1 | ForEach-Object -Process `
{
if ($_ -is [System.Management.Automation.ErrorRecord])
{
"$StderrPrefix$_"
}
else
{
"$_"
}
}
if ($AllowedExitCodes -notcontains $LASTEXITCODE)
{
throw "Execution failed with exit code $LASTEXITCODE"
}
}
finally
{
$script:ErrorActionPreference = $backupErrorActionPreference
}
}