-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBuild_Full_CheckScript.ps1
36 lines (28 loc) · 1.55 KB
/
Build_Full_CheckScript.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Param
(
[string]$OutputScriptFilePath = "Full_Check_Script.sql"
,[string]$TemplateHeaderFilePath = "Template/Template_Header.sql"
,[string]$TemplateFooterFilePath = "Template/Template_Footer.sql"
,[string]$CheckTemplateHeaderFilePath = "Template/Check_Header.sql"
,[string]$CheckTemplateFooterFilePath = "Template/Check_Footer.sql"
,[string]$CheckScriptsFolderPath = "SQLChecks\*"
,[string]$CheckScriptsFilter = "*.sql"
)
$batchSeparator = "`r`nGO`r`n"
$OutputScriptBuilder = [string](Get-Content -Path $TemplateHeaderFilePath -Raw)
$CheckHeaderTemplate = [string](Get-Content -Path $CheckTemplateHeaderFilePath -Raw)
$CheckFooterTemplate = [string](Get-Content -Path $CheckTemplateFooterFilePath -Raw)
[int]$CheckId = 0
Get-ChildItem -Path $CheckScriptsFolderPath -Include $CheckScriptsFilter | ForEach-Object {
$CheckId += 1
$CheckTitle = $($_.BaseName)
Write-Output "Check $CheckId : $CheckTitle"
$OutputScriptBuilder += $batchSeparator
$OutputScriptBuilder += $CheckHeaderTemplate.Replace('{CheckId}', $CheckId).Replace('{CheckTitle}', $CheckTitle)
$OutputScriptBuilder += [string](Get-Content -Path $_.FullName -Raw).Replace('{CheckId}', $CheckId).Replace('{CheckTitle}', $CheckTitle)
$OutputScriptBuilder += $CheckFooterTemplate.Replace('{CheckId}', $CheckId).Replace('{CheckTitle}', $CheckTitle)
}
Write-Output "Finalizing output script: $OutputScriptFilePath"
$OutputScriptBuilder += $batchSeparator
$OutputScriptBuilder += [string](Get-Content -Path $TemplateFooterFilePath -Raw)
$OutputScriptBuilder | Out-File $OutputScriptFilePath -Force