#1 26 Jul 2011 01:45

sergi0
Member
Registered: 26 Jul 2011
Posts: 1

Out-File

Hi I am pretty new to using PowerShell 2.0. I am trying everything I can to learn it quickly; however, I've been trying to learn how to use the Out-File to more or less print or save to a file a particular file tree.  When I run the command (PS C:\1> out-file -filepath c:\testoutfile.txt) the command creates the file I specified (testoutfile.txt) but none of the data I have in my folder are not displaying on my out-file results it's just a blank text file. In a nut shell, how do I use the Out-file command to print out or save to a file a folder tree structure.  Thanks for your help.

Offline

#2 26 Jul 2011 23:01

Simon Sheppard
Super Administrator
Registered: 27 Aug 2005
Posts: 1,041
Website

Re: Out-File

$stuff = dir -recurse "C:\work\" | select fullname
$stuff | out-file F:\found.txt

or alternatively

$stuff = dir -recurse "C:\work\" | select fullname
$stuff > F:\found.txt

The reason you need to use '| select fullname' is that dir (or Get-ChildItem) returns an object with a multitude of properties, so its best to specify which ones you want up front. This is actually a lot easier than trying to parse a pure text output the way you would have to with CMD.

To see all the properties and methods available use

dir | get-member

Offline

Board footer

Powered by FluxBB