Skip to content

Instantly share code, notes, and snippets.

Created January 10, 2013 01:14
Show Gist options
  • Save anonymous/4498559 to your computer and use it in GitHub Desktop.
Save anonymous/4498559 to your computer and use it in GitHub Desktop.
#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