powershellpowershell-2.0

Get full path of the files in PowerShell


I need to get all the files including the files present in the subfolders that belong to a particular type.

I am doing something like this, using Get-ChildItem:

Get-ChildItem "C:\windows\System32" -Recurse | where {$_.extension -eq ".txt"}

However, it's only returning me the files names and not the entire path.


Solution

  • Add | select FullName to the end of your line above. If you need to actually do something with that afterwards, you might have to pipe it into a foreach loop, like so:

    get-childitem "C:\windows\System32" -recurse | where {$_.extension -eq ".txt"} | % {
         Write-Host $_.FullName
    }