Stairway to SQL Server Agent - Level 8: Using External programs with SQL Server Agent

  • Richard Waymire

    SSC Eights!

    Points: 919

    Comments posted to this topic are about the item Stairway to SQL Server Agent - Level 8: Using External programs with SQL Server Agent

  • mario.granzella

    SSC Enthusiast

    Points: 103

    Hi Richard,

    I'm new with PowerShell. I'm doing some test and I have a question about the step 2 of this job. Where is the output of the PowerShell script?

    Best regards and happy new year!

    MARIO

  • pkrudysz

    Right there with Babe

    Points: 742

    Agree and disagree: 🙂 🙁

    "repetitive tasks, or as in the case of CmdExec, any task that leaves the SQL Server environment is much simpler from the PowerShell subsystem.

    Disagree:

    Any repetitive SQL Server task can be easily done using t-sql inside SQL Server - that's what you have SQL Server Agent for!

    Agree:

    Tasks that leave the SQL Server environment - here PowerShell might be worth exploring.

  • Richard Waymire

    SSC Eights!

    Points: 919

    By default the output in SQL Server Agent goes to the msdb.dbo.sysjobhistory table (that's what you see when you ask to view history from the job).

    To get the output somewhere else, there are a number of possibilities, for example you could do this:

    $server = new-object( 'Microsoft.SqlServer.Management.Smo.Server' ) “(local)”

    foreach ($database in $server.databases)

    {

    $dbName = $database.Name

    Write-Output "Database: $dbName" | Out-File c:\temp\temp.txt -append

    }

    Which will create and then append results to teh file c:\temp\temp.txt with the list of database names.

  • mario.granzella

    SSC Enthusiast

    Points: 103

    Thanks Richar. I'll try it.

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

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