Skip to content

Instantly share code, notes, and snippets.

@underwhelmed
Created May 4, 2010 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save underwhelmed/389767 to your computer and use it in GitHub Desktop.
Save underwhelmed/389767 to your computer and use it in GitHub Desktop.
$server = "localhost"; # The SQL Server instance name
$database = "MyDB"; # The database name
# Load the SMO assembly
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.SMO") | out-null
# Create the SMO objects
$srv = New-Object "Microsoft.SqlServer.Management.SMO.Server" $server;
$db = New-Object ("Microsoft.SqlServer.Management.SMO.Database");
# Get the database
$db = $srv.Databases[$database];
# For each stored procedure in the database
foreach($proc in $db.StoredProcedures)
{
# NOTE: my stored procedures are all prefixed with "web_"
if ($proc.Name.StartsWith("web_"))
{
$proc.TextBody = $proc.TextBody;
$proc.Alter();
Write-Host "Altered " $proc.Name;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment