Search code examples
xmlexcelpowershellregistry

Read a registry key to get values for macro to run automatically multiple files with powershell


I have problems to transfer the values of the xml-file to the "macro", that needs these paths (content of the xml) to work with.

I use powershell to run the personal macro on multiple files and that worked out perfectly till the point I added the xml-file to read out the pathes.

Powershell-Script Error message after running the script

Here`s the XML-File:

<?xml version="1.0" encoding="UTF-8"?>
   <Reports>
     <Report>
        <Report_Path>"C:\Users\famichalsk\Desktop\Versuch1\C2.1.1.F003 KS05599 Project Data Plan.xlsm"</Report_Path>
     </Report>
     <Report>
        <Report_Path>"C:\Users\famichalsk\Desktop\Versuch1\C2.1.1.F003-PDP-KS05917.xlsm"</Report_Path>
     </Report>
     <Report>
        <Report_Path>"C:\Users\famichalsk\Desktop\Versuch1\C2.1.1.F003-PDP-KS03451.xlsm"</Report_Path>
     </Report>
   </Reports>

Solution

  • foreach($FilePath in $report.Reports.Report.Report_Path){
         ....
         $workbook = $excel.workbooks.open($FilePath)
         ....
    }
    

    And your paths should not include the double-quotes.