Repeating header in Weekend Scripter: How Can I Create, Display, and Then Delete a Temporary Text File?

It seems that the script output repeats the header line for each item in the pipeline. In case of "dir c:\windows | out-tempfile" it actually prints multiple lines before each item.

It is not obvious why. I tried debugging the script and each items comes without the header line (s).

Thank you

Alex.

August 28th, 2015 11:49am

Hi Alex,

What script are you referring to?

Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 12:03pm

http://blogs.technet.com/b/heyscriptingguy/archive/2010/07/18/hey-scripting-guy-weekend-scripter-how-can-i-create-display-and-then-delete-a-temporary-text-file.aspx

Thanks for your time!

August 28th, 2015 12:06pm

I am running the script as dir c:\windows | out-tempfile.

I expected to see the directory listing in notepad, but the output is different from cmd console and from ISE console. It adds directory header lines to each entry.

I tried adding " write-output $in " prints one line with current file info. When I stop in debugger and print $in it prints directory header lines plus the line for the current item.

It seems to be related to console output mode, not to script itself.

Free Windows Admin Tool Kit Click here and download it now
August 28th, 2015 12:17pm

That is a very old post (more that 5 years) and was not intended to be a good CmdLet but an example of how to write an advanced function.

To output formatted objects do this:

dir c:\windows  | Format-Table -auto | Out-String | Out-File mylisting.txt

August 28th, 2015 12:19pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics