There’s a question on this already (here). But I’m hoping that because I’m using PowerShell 2, and SQL Server 2008, that I might get different answers if I ask again.
Basically, I have a SQL Server Agent job, which runs a cmd script like so:
powershell "&D:\SQL\Job\JobDir\Upload.ps1 (various arguments including log file name)"
When it runs start-transcript, the file is created, but nothing except a header is written to the file. However, when I run on the command line, everything is logged properly.
I’ve already got lots of logic to manage old log files in the powershell script, and don’t want to just use the default logging that SQL Server Agent provides.
To write out info, I use invoke-sqlcmd with the verbose flag, and also write-message and write-error.
Thanks for any pointers!
Sylvia
Permissions were not an issue for me. I think there’s ways of manipulating the output from powershell very exactly, with all the different output streams (error, verbose, etc), but instead of getting into those details, I just used the default logging that SQL Server agent provides for each job step. It works okay. I still use the logic that I wrote to manage and archive log files in my script, I can do that even though the log file itself is generated by SQL Server.