SQLPS vs SSMS

  • Ran into a SNAFU. I have a simple script that will "create" creation scripts for any object in an object folder.

    (get-childitem | %{$_.Script()} > C:\temp\whatever.sql)

    Let's use the example I want to script all my JOBS to be recreated on another server. It should be you run this script, load the "whatever" on another server and "there ya go'. But, right after the first job is created the sql failures begin. I looked a little closer and found the script generation leaves out the GO command that should be there just prior to the next BEGIN TRANSACTION. No problem, I use WORD and a little Find/Replace magic and we're good to go. (BTW check out ^c in the Replace box)

    If you open the Detailed Obj Expl in SSMS and highlight all the jobs, you can right click and get the same script except the GO is there. Since Microsoft uses PowerShell under the covers I never expected this result. Did I miss something or is this a no go plan?

    I guess I could extend the script to put the GO in , but REALLY...

  • actually, both powershell and ssms are using smo under the covers.

    the batch separator is an option you can select, i believe.

    $Scripter.Options.ScriptBatchTerminator=$true

    $Scripter.Options.NoCommandTerminator=$false

    see this thread for an example on teh same question:

    http://www.sqlservercentral.com/Forums/Topic996028-1351-1.aspx#bm996236

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply