Quantcast
Channel: Active questions tagged windows - Super User
Viewing all articles
Browse latest Browse all 9673

How to Find and Recursively Read Files Using Powershell?

$
0
0

I'm new to PowerShell and trying to recursively find XML files in a directory and read (or cat in unix) each file.

If this were a linux machine, I'd do something like:

$ find /path/to/dir/ -type f -iname *.xml -exec cat {} \;

I've been trying PowerShell's Get-Content and Get-ChildItem but I'm not having much luck:

powershell Get-ChildItem -Path C:\ProgramData\Microsoft\ -Include *.xml -Recurse | ForEach-Object {Write-Output $_; Get-Content $_}

Could someone help me figure out what I'm doing wrong or offer a simpler solution for finding and recursively reading files in a directory?


Viewing all articles
Browse latest Browse all 9673