How to get file contain of innertext of xml using PowerShell? RRS feed

  • Question

  • Hello everyone.  I want to get a file if the file contain of innertext xml file. If the innertext only one, I can get it, but once I have 2 innertext, it means I wan to get 2 file, It does not work. Is anyone can give me advice? Wheteher I can use this way or not. Thank you.

    [xml]$File = Get-Content -Path .\filecontent.xml
    $xml_inner = $File.Title.FileName
    $xml_inner = $xml_inner.InnerText
    $getfile = Get-ChildItem -Path .\file | Where-Object {$_.FullName -match "$xml_inner" }

    The xml file is like this

    <?xml version="1.0" encoding="UTF-8"?>

    Thursday, December 5, 2019 10:02 AM

All replies

  • Try below:

    [xml]$File = Get-Content -Path .\filecontent.xml
    $xml_inner = $File.Title.FileName.ChildNodes | Select-Object -ExpandProperty "#text"
    cd .\file
    $xml_inner | foreach {
            Get-ChildItem -Path $_ 

    Thursday, December 5, 2019 11:21 AM
  • How if I define the path of the. ./file as a variable and I want to set as a variable for the file that I get as well? I dont want to use this way `cd .\file` Thank you. Need advice please
    • Edited by Fsbr Friday, December 6, 2019 1:59 AM
    Thursday, December 5, 2019 3:58 PM