Forked from anonymous/Set-FileGroupSpecification.ps1
Created
January 10, 2013 02:07
-
-
Save stephengodbold/4498778 to your computer and use it in GitHub Desktop.
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
#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
This gist is intended to work on the file structure of a .table.sql file with a separate file for the indexes. It will not resolve where indexes are stored in the table file at this point.