Microsoft Windows
Post Reply
User avatar
Posts: 336
Joined: 2021-Jul-12, 1:37 pm


Post by MigrationUser »

26 Jul 2011 01:45

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.


#26 Jul 2011 23:01
Simon Sheppard

Code: Select all

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

Code: Select all

$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
Post Reply