I have a script I created that contains considerable output to the console using Write-Host. I start a transcript at the beginning of the script and all output from Wrote-Host is contained in the transcript file.
However, yesterday I made some revisions (primarily to not present message boxes) if the account that executed the script is disconnected, and sceduled the script to be executed as a job under SQL Agent. This morning, when I got in and examined the transcript file, it contained the following, with none of the output from Write-Host. I have executed the script multiple times manually, and disconnected from the machine without any loss of output, so not sure what I need to do, but I need to force the output to the transcript file, along with any output that the script might generate. Is there something I need to use instead of Write-Host?
**********************Windows PowerShell transcript startStart time: 20150311180206Username : computername\_sqlagentMachine : computername (Microsoft Windows NT 6.1.7601 Service Pack 1)********************************************Windows PowerShell transcript endEnd time: 20150312013540**********************
When its run from the sql agent, I believe it's not opening a command window so there is nothing to transcribe. What you may need to do instead is output the results and append to a log file like so
If you could post what you are doing in the script, we may be able to help out a little more.
Qlemo
In general, don't use the transcript option. You should use Out-File, Write-Output and the like. Write-Host is only useful for the interactive console window; any other PS host might or might not take output with Write-Host.
D B
ASKER
Basicly I am using write-host to output data to the console. It may be straight text such as:
write-host "starting the process"
a combination of text and a variable such as:
write-host "executing step $stepname"
or a variable such as:
write-host "$message"
In any case, is there a way to determine if a command window is available (e.g. it was run from SQL Agent)?
Open in new window
or you can use
Open in new window
If you could post what you are doing in the script, we may be able to help out a little more.