Skip to content

Instantly share code, notes, and snippets.

@kenzauros
Created April 26, 2023 00:31
Show Gist options
  • Save kenzauros/746587214fbd97431860e9a6bf558930 to your computer and use it in GitHub Desktop.
Save kenzauros/746587214fbd97431860e9a6bf558930 to your computer and use it in GitHub Desktop.
SQL 結合用 PowerShell スクリプト
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