Powershell Transcript is empty when running script from SQL Agent Job in 2005 SQL Server

Posted by Greg Bray on Stack Overflow See other posts from Stack Overflow or by Greg Bray
Published on 2010-03-04T23:54:01Z Indexed on 2010/03/30 0:13 UTC
Read the original article Hit count: 1010

I have a complex Powershell script that gets run as part of a SQL 2005 Server Agent Job. The script works fine, but it uses the "Start-Transcript $strLogfile -Append" command to log all of it's actions to a transcript file. The problem is that the transcript is always empty. It adds the header and footer to indicate that the transcript is starting and stopping, but it doesn't actually log anything. Example:

**********************
Windows PowerShell Transcript Start
Start time: 20100304173001
Username  : xxxxxxxxxxxx\SYSTEM 
Machine   : xxxxx-xxx (Microsoft Windows NT 5.2.3790 Service Pack 2) 
**********************
**********************
Windows PowerShell Transcript End
End time: 20100304173118
**********************

When I execute the script from a command prompt or start -> run everything works just fine. Here is the command used to run the script (same command used in the Operating system CmdExec step of the SQL Agent Job)

powershell.exe -File "c:\temp\Backup\backup script.ps1"

I first thought it must have something to do with the script running under the System account (default SQL Agent account), but even when I tried changing the SQL Agent to run under my own personal account it still created a blank transcript.

Is there any way to get PowerShell Transcripts to work when executing them as part of a 2005 SQL Server Agent Job?

© Stack Overflow or respective owner

Related posts about powershell

Related posts about sql-server-2005