Created
July 25, 2017 21:56
-
-
Save bforrest/61610205641d34e7951a8a20d34f4117 to your computer and use it in GitHub Desktop.
script stored procs to a file
This file contains hidden or 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
pushd; | |
import-module sqlps -disablenamechecking; | |
popd; | |
$s = new-object microsoft.sqlserver.management.smo.server 'localhost'; | |
$db = $s.Databases['ps_all_the_things']; | |
foreach ($proc in $db.StoredProcedures | where {($_.IsSystemObject -eq $false) -and ($_.Schema -eq 'dbo')}) { | |
$file = 'd:\temp\' + $proc.Name + '.sql'; | |
Write-Host $proc.Name; | |
$proc.script() | Out-File $file; | |
} | |
$a = $s.JobServer; | |
foreach ($job in $a.Jobs) { | |
$job.script(); | |
} | |
$s = new-object microsoft.sqlserver.management.smo.server 'localhost'; | |
$db = $s.Databases['demoDb']; | |
foreach ($proc in $db.StoredProcedures | | |
where {$_.Schema -eq 'dbo'}) { | |
$file = 'd:\temp\' + $proc.Name + '.sql'; | |
Write-Host $proc.Name; | |
$proc.script() | Out-File $file; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment