Skip to content

Instantly share code, notes, and snippets.

@kenzauros
Last active February 14, 2022 02:40
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 kenzauros/6c6aad4ad938ece7deefabc0e6d6585a to your computer and use it in GitHub Desktop.
Save kenzauros/6c6aad4ad938ece7deefabc0e6d6585a to your computer and use it in GitHub Desktop.
ディレクトリ内の SQL ファイルを結合する PowerShell スクリプト (SQL Server 用)
Param(
[parameter(mandatory)][String]$outputFile
)
$divider="-- $("=" * 100)"
$files = Get-ChildItem .\*.* -Include *.sql -Exclude $outputFile
if (Test-Path $outputFile) { Clear-Content $outputFile }
function output {
process {
Out-File -Encoding UTF8 -FilePath $outputFile -Append -InputObject $PSItem
}
}
foreach ($file in $files) {
Write-Output $divider | output
Write-Output "-- $($file.Name)" | output
Write-Output $divider | output
Get-Content $file.FullName -Encoding UTF8 `
| Select-String -Pattern "^(BEGIN TRAN|ROLLBACK)" -NotMatch `
| Select-Object -ExpandProperty line | output
Write-Output "GO`r`n" | output
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment