PowerShell: Enumerate Files recursive and get full path for each file

To enumerate all files of a specific path recursive and get the full path for each file using Microsoft PowerShell:


Get-ChildItem -rec | ForEach-Object -Process {$_.FullName}

to capture the output and generate an XML file do:


Get-ChildItem -rec | ForEach-Object -Process {$_.FullName} | Export-Clixml c:\temp\report.xml

to only enumerate / list files, use the psIsContainer switch:


Get-ChildItem -rec | Where-object {!$_.psIsContainer -eq $true} | ForEach-Object -Process {$_.FullName}

or for folders only:


Get-ChildItem -rec | Where-object {!$_.psIsContainer -eq $false} | ForEach-Object -Process {$_.FullName}

4 thoughts on “PowerShell: Enumerate Files recursive and get full path for each file

  1. Your code to select folders only or files only can be shortened a little:
    Files only: gci -rec | where {!($_.PSIsContainer)}
    Folders only: gci -rec | where {$_.PSIsContainer}

  2. Thanks this article really helps, I can believe that a simple:
    grep -lir “*.js” .

    In powershell can be:
    Get-ChildItem -rec | Where-object {!$_.psIsContainer -eq $true -and $_.FullName -like “*.js”} | ForEach-Object -Process {$_.FullName}

  3. mind the wrap round but this should forma reasonable core script returning full file paths:

    cls
    $PSQLpath = @()
    $PSQLpath = dir d:\ -recurse -Filter psql.exe|Select-Object fullname |ft -HideTableHeaders
    $PSQLpath

  4. @chrisboot
    “Thanks this article really helps, I can believe that a simple:
    grep -lir “*.js” .

    In powershell can be:
    Get-ChildItem -rec | Where-object {!$_.psIsContainer -eq $true -and $_.FullName -like “*.js”} | ForEach-Object -Process {$_.FullName}”

    There’s a big difference here. Your simple grep really is simple because it’s only parsing text. Powershell is handling Objects, not grepping text, which it COULD do with a simple “| find *.js”.

Leave a Reply

Your email address will not be published. Required fields are marked *