Comments posted to this topic are about the item Stairway to SQL Server Agent - Level 8: Using External programs with SQL Server Agent
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!
Right there with Babe
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.
Any repetitive SQL Server task can be easily done using t-sql inside SQL Server - that's what you have SQL Server Agent for!
Tasks that leave the SQL Server environment - here PowerShell might be worth exploring.
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.
Thanks Richar. I'll try it.
Viewing 5 posts - 1 through 4 (of 4 total)