Skip to content

August 4, 2009

3

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
3 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}

Share your thoughts, post a comment.

(required)
(required)

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

Subscribe to comments