简体   繁体   English

Powershell跟踪和控制-M

[英]Powershell Tracing and Control-M

I seem to have run into a problem/bug when trying to capture tracing output when running a Powershell script from Control-M. 从Control-M运行Powershell脚本时,尝试捕获跟踪输出时,我似乎遇到了问题/错误。

The output file shows the headers and footers of the start-trace and stop-trace commands, but it does not show anything else I try to capture. 输出文件显示了开始跟踪和停止跟踪命令的页眉和页脚,但未显示我尝试捕获的其他任何文件。 Specifically, if my script issues a write-host command somewhere, then that information is not captured in the output (trace) file. 具体来说,如果我的脚本在某个地方发出了写主机命令,则该信息不会捕获到输出(跟踪)文件中。

Here is a super simple script that illustraes my problem: 这是一个说明我问题的超简单脚本:

start-transcript -path "C:\Powershell\transcript.log"
write-host "test message"
#do stuff...
stop-transcript

Here is an example of my current output when running the script through Control-M: 这是通过Control-M运行脚本时当前输出的示例:

**********************
Windows PowerShell Transcript Start
Start time: 20140212002005
Username  : mydomain\SYSTEM 
Machine   : myserver (Microsoft Windows NT 6.1.7601 Service Pack 1) 
**********************
**********************
Windows PowerShell Transcript End
End time: 20140212002008
**********************

Note that my test message does not show up! 请注意,我的测试消息没有显示! This only happens when I run the script via Control-M. 这仅在我通过Control-M运行脚本时发生。 When I run my script manually, my "test message" does show up in the transcript output. 当我手动运行脚本时,我的“测试消息”确实显示在脚本输出中。

My first suspicion was file permissions, but those look good to me. 我的第一个怀疑是文件权限,但是这些对我来说看起来不错。 The Control-M agent uses system level access, so it should have all the permissions it needs anyway. Control-M代理使用系统级访问,因此无论如何它都应具有所需的所有权限。 If it were a file permission issue, I don't believe i would even get the header/footer messages. 如果是文件权限问题,我不相信我什至会收到页眉/页脚消息。

I'm on PS v2.0. 我正在使用PS v2.0。 My server is running 2008r2. 我的服务器正在运行2008r2。

Any thoughts appreciated... 任何想法表示赞赏...

Write-Host writes to to the console window, which is not what's being "watched" by Control-M. Write-Host写入控制台窗口,而不是Control-M监视的窗口。 Try Write-Output instead. 请尝试使用Write-Output Write-Host is usually not what you want for producing output. Write-Host通常不是您想要产生输出的内容。

See http://windowsitpro.com/blog/what-do-not-do-powershell-part-1 and http://powershell.com/cs/blogs/donjones/archive/2012/04/06/2012-scripting-games-commentary-stop-using-write-host.aspx 参见http://windowsitpro.com/blog/what-do-not-do-powershell-part-1http://powershell.com/cs/blogs/donjones/archive/2012/04/06/2012-scripting使用-games -评论-停止-写host.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM