Skip to content

August 4, 2009


Export List of File Names with PowerShell

Here’s a quick and easy little function to get a list of files (and their paths) using PowerShell.

Function GetFileNames([string]$path, [string]$outputFile) {
  $list = Get-ChildItem $path -Recurse
  $list | Select-Object BaseName, FullName | Export-Csv $outputFile

GetFileNames ".\" "C:\Output.csv"
Read more from PowerShell
4 Comments Post a comment
  1. Afif Khaja
    Jul 10 2017

    Perfect and well-written code. Thank you!

  2. Jaan Deen
    Nov 15 2017

    Still useful in 2017!! Better organized code than what I found on the Net.

  3. Jaan Deen
    Nov 15 2017

    If you do *not* want the empty folder names… and only a file name list… remodify this line to the following:

    $list = Get-ChildItem $path -Recurse | where {!$_.PSIsContainer}

  4. Akarsh Verma
    Aug 3 2018

    Great work… I have taken the liberty of creating a public gist for this. Do let me know if that is a concern.

Share your thoughts, post a comment.


Note: HTML is allowed. Your email address will never be published.

Subscribe to comments