header
header Register : : Login header
header
divider
menuleft
menuright
submenu
left

 

Subject: Logging screen output to file when running script
Prev Next
You are not authorized to post a reply.

Author Messages
Box293User is Offline
New Member
New Member
Posts:8

03/06/2008 3:04 PM  

I have generated a script that is about 800 lines long. The script asks the user a few questions intially and then goes off and does it's stuff.

In a perfect world the script always works but if it spits an error out it usually disappears off the screen before the user gets a chance to make a note of it.

I would like the script to be able to output everything it displays on the screen to a log file as well, this way we can review it later if need be.

Currently I call the script the following way:

C:\WINDOWS\system32\WindowsPowerShell\v1.0\PowerShell.exe -PSConsoleFile "C:\Program Files\Microsoft\Exchange Server\bin\exshell.psc1" -command ". 'C:\PowerShellScripts\Test.ps1'"

 

Thanks

Troy

bsonposhUser is Offline
CLI Addict
CLI Addict
Posts:346

03/06/2008 3:26 PM  
take a look at
start-transcript
and
stop-transcript

Brandon Shell
----------------
Microsoft Powershell MVP
https://mvp.support.microsoft.com/profile/Brandon
Box293User is Offline
New Member
New Member
Posts:8

03/06/2008 4:49 PM  

Excellent, that does exactly what I am after. Is there anything that PowerShell can't do ??? ;o)

FYI here is the code I used:

$DateTime = Get-Date -format "yyyy-MM-dd HH.mm.ss"
$LogName = "Create New Client Script Run @ "+"$DateTime"+".txt"
Start-Transcript -path "${env:logonserver}\NETLOGON\Scripts\Common\Logs\$LogName"

And then Stop-Transcript at the end.

Thanks very much for the response.

kscrissUser is Offline
Power User
Power User
Posts:122


03/10/2008 11:15 AM  
Cool. I didn't know that either.

My blog: http://blogs.powershellcentral.com/kscriss/
Box293User is Offline
New Member
New Member
Posts:8

03/10/2008 12:58 PM  

I like Powershell more and more every day. As long as I have a resource like this to ask people how to do things I am able to get the most out of it.

You are not authorized to post a reply.
Forums > Using PowerShell > General PowerShell > Logging screen output to file when running script



ActiveForums 3.7
right
   
footer Sponsored by Quest Software • SAPIEN Technologies • ShellTools, LLC • Microsoft Windows Server 2008 footer
footer