Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

Copy text from one file into another at a specific possition using Powershell - Having trouble with Select-String -Pattern

$
0
0

Hello And thank you in advance for any help this community can provide!

I'm trying to create a powershell script that will copy the "excel.officeUI" file from a network drive, to a users local drive into the "C:\Users\%UserID%\AppData\Local\Microsoft\Office"  folder, but If the file already exists, I just want it to copy a specific portion of the file and append it to the local one that already exists

In the File, there is a bunch of headers that are the same, but then it shows <mso:tab id="mso_c2.3ED4DC" label="Macros" insertBeforeQ="mso:TabHome">.... and all the information about the custom ribbon I created in Excel appear all the way to </mso:tab>

So I want to take everything that is between <mso:tab id=".... to </mso:tab> and copy that into the "excel.officeUI" file on their local workstation, and enter it right before the </mso:tabs> (The final tag for the Tabs) so I don't disrupt any custom ribbons they might have already created.

If you are still following me up to here, thank you for your patience :)

So here is the code I'm trying to use but for some reason, it does not find the text I'm looking for and it might have to do with the way I'm entering the "-pattern ..." portion or the fact that the file might have multiple locations where <mso:tab id="... exists:

$copyMacroText = Get-Content $NetExcelFile | Select-String  -Pattern '<mso:tab .*?</mso:tab>' |
               select -expandproperty matches |
               select value


$replaceDestinationText = Get-Content $localExcelFile | Select-String  -Pattern $msoFinal |
               select -expandproperty matches |
               select value

Hopefully this is something very simple that I'm missing!

Thank you!

Alex


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>