Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#requires -Version 2.0
param(
[Parameter(Mandatory=$true)]
[string]
$databaseRootDirectory
)
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version 'Latest'
$fileGroupSpecification = "ON [PRIMARY]"
$fileGroupSpecificationPattern = "ON \[PRIMARY\]"
function Test-FileGroupSpecification {
param(
[Parameter(Mandatory=$true)]
[string]
$tablePath
)
Get-ChildItem $tablePath -Recurse -File -Exclude *table.sql | foreach {
$content = Get-Content $_.PSPath | Out-String
if ($content -match $fileGroupSpecificationPattern ) {
return $true
}
}
return $false
}
$tableScripts = Get-ChildItem $databaseRootDirectory -Recurse -Filter *.table.sql
$tableScripts | foreach {
$content = Get-Content $_.PSPath | Out-String
if ($content -match $fileGroupSpecificationPattern) {
if (Test-FileGroupSpecification $_.PSParentPath) {
$updatedContent = $content.Replace($fileGroupSpecification, '')
Set-Content $tableFilePath -Value $updatedContent
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment