0

I want to display the content of all the XML files present in a folder one by one. Commands I am using are:

$test = Get-ChildItem | Select-Object -Property Name
foreach ($i in $test) {
    Get-Content $i
}

but it is not working as expected. It is throwing an error saying:

Cannot find path \<dir_path>\@{Name=<filename>.xml} because it does not exist

0

1 Answer 1

3

Get-Content is wildcard aware so you can display them with simply:

Get-Content *.xml

If you want to perform a more complex action or perhaps separate them you could use something like:

Get-ChildItem *.xml -file | ForEach-Object { 
  Write-Warning ("`n    $($_.FullName) `n" + '=' * 72)
  Get-Content $_.fullName
}

This is just an example of what you might do to separate the files visually or perform any other action -- you could stop and wait for a keypress etc....

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.