Solved

Powershell script to output a list of files that are in folders and subfolers.

Posted on 2011-09-30
2
471 Views
Last Modified: 2012-08-13
Hi,

I need to write a power shell script that will output to a text file all the files that are in a directory including files in sub folders. .

Thanks

Luke
0
Comment
Question by:luketr
2 Comments
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
Comment Utility

You can use the recurse switch to get all subfolder and then pipe to where to check if it is a file or folder.

Get-ChildItem c:\temp -Recurse | Where {$_.PSISContainer -ne $True} | out-file c:\temp\files.txt

Or CSV File

Get-ChildItem c:\temp -Recurse | Where {$_.PSISContainer -ne $True} | export-csv c:\temp\files.csv
0
 
LVL 68

Expert Comment

by:Qlemo
Comment Utility
Since PSIsContainer is a boolean value, it is more straightforward to omit comparision (which is redundant):
Get-ChildItem c:\temp -Recurse | Where {!$_.PSIsContainer} | out-file c:\temp\files.txt

Open in new window

You can use aliases, which are a matter of taste:
gci c:\temp -recurse | ? {!$PSIsContainer] | out-file c:\temp\files.txt

Open in new window

0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Hi all.   The other day I had to change the passwords for a bunch of users on the fly. Because they were so many, I decided to do it in an automated way and I would like to share it with you all.   If you are not doing it directly in a Domain Co…
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now