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}

One thought 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}

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">