2

I'm currently using the Out-File cmdlet, like so:

PS> Some-Cmdlet -someswitch | Out-File -filepath .\somefile.txt

It works great.

Is there anyway that I can actually get the command line itself to print to the same file before the output?

In other words, when I open somefile.txt I want to see the following:

Some-Cmdlet -someswitch | Out-File -filepath .\somefile.txt

OUTPUT
OUTPUT
OUTPUT
etc.
Daniel
  • 1,614
  • 9
  • 29
  • 47

1 Answers1

3

I think you're looking for start-transcript:

The Start-Transcript cmdlet creates a record of all or part of a Windows PowerShell session in a text file. The transcript includes all command that the user types and all output that appears on the console.

So you'd want to do:

start-transcript -path c:\temp\transcript.txt -noclobber

... do sume stuff ...

stop-transcript
pacey
  • 3,833
  • 1
  • 16
  • 31