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?

  • The command looks ok to me. What error are you getting? Does it work when you execute the command in the Powershell ISE? Following at least works on my system gci C:\ProgramData\Microsoft\ -i *.xml -r | % { gc $_} – Lieven Keersmaekers Feb 15 '18 at 5:48
  • i get the error "Get-Content : Cannot bind argument to parameter 'Path' because it is an empty string." when using your command and modified version of my own. i dont get why its saying the path is an empty string. what do you think? – Cathy Feb 15 '18 at 5:57
  • I would try using another folder and enclose it in parentheses. Does following return anything gci "C:\" -i *.xml -r – Lieven Keersmaekers Feb 15 '18 at 6:01
  • Yup! quotes did the trick. weird. thanks so much for your help. would you have a minute to look at my other superuser question? superuser.com/questions/1295125/… – Cathy Feb 15 '18 at 6:09
  • 1
    Your question can be improved by adding what the curl command is supposed to do. The -F is to specify HTTP multipart POST data apparently. I have no idea what that means. – Lieven Keersmaekers Feb 15 '18 at 6:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.