Solved

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

Posted on 2011-09-30
2
478 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
ID: 36891024

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 69

Expert Comment

by:Qlemo
ID: 36891061
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
check java version using powershell 13 85
Shutdown Inactive Server- Script 4 18
powershell md/mkdir/New-item   -Quiet 10 40
powershell and invoke-command 4 20
This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…

776 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