October 15, 2011 at 3:07 pm
Comments posted to this topic are about the item Stairway to SQL Server Agent - Level 8: Using External programs with SQL Server Agent
December 29, 2011 at 7:25 am
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
January 3, 2012 at 9:19 am
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.
January 3, 2012 at 10:05 am
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.
January 3, 2012 at 10:07 am
Thanks Richar. I'll try it.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply