Last active
February 14, 2022 02:40
-
-
Save kenzauros/6c6aad4ad938ece7deefabc0e6d6585a to your computer and use it in GitHub Desktop.
ディレクトリ内の SQL ファイルを結合する PowerShell スクリプト (SQL Server 用)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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