在 2005 SQL Server 中从 SQL 代理作业运行脚本时,Powershell Transcript 为空 [英] Powershell Transcript is empty when running script from SQL Agent Job in 2005 SQL Server

查看:33
本文介绍了在 2005 SQL Server 中从 SQL 代理作业运行脚本时,Powershell Transcript 为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复杂的 Powershell 脚本,它作为 SQL 2005 服务器代理作业的一部分运行.该脚本运行良好,但它使用Start-Transcript $strLogfile -Append"命令将其所有操作记录到脚本文件中.问题是成绩单总是空的.它添加了页眉和页脚以指示抄本正在开始和停止,但实际上并没有记录任何内容.示例:

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
**********************

当我从命令提示符或开始执行脚本时 -> 运行一切正常.这是用于运行脚本的命令(与 SQL 代理作业的操作系统 CmdExec 步骤中使用的命令相同)

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"

我首先认为它一定与在系统帐户(默认 SQL 代理帐户)下运行的脚本有关,但即使当我尝试将 SQL 代理更改为在我自己的个人帐户下运行时,它仍然创建了一个空白的脚本.

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.

在将 PowerShell Transcripts 作为 2005 SQL Server 代理作业的一部分执行时,有没有办法让它们工作?

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

推荐答案

我仍然不确定为什么 Powershell Transcript 为空,但我们找到了解决方法.在 SQL 作业的 CmdExec 步骤下,有一个将输出捕获到文件的高级选项,该选项与将输出附加到现有文件"选项相结合,并使用 Logfile.rtf 扩展名与 Powershell 脚本大致相同.这样,从 Powershell 脚本打印到主机的任何内容(包括通过管道传输到| out-host"的本机控制台可执行文件)都将被记录在日志文件中.

I am still not sure why the Powershell Transcript is empty, but we found a workaround. Under the CmdExec step of the SQL Job there is an advance option to capture the output to a file, which combined with the "Append output to existing file" option and using a Logfile.rtf extension is about the same as the Powershell transcript. This way anything that gets printed to the host from the Powershell script (including native console executables piped to "| out-host") will be captured in the log file.

这篇关于在 2005 SQL Server 中从 SQL 代理作业运行脚本时,Powershell Transcript 为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆