Copy text from one file into another at a specific possition using Powershell - Having trouble with Select-String -Pattern
hello , thank in advance community can provide!
i'm trying create powershell script copy "excel.officeui" file network drive, users local drive "c:\users\%userid%\appdata\local\microsoft\office" folder, if file exists, want copy specific portion of file , append local 1 exists
in file, there bunch of headers same, shows <mso:tab id="mso_c2.3ed4dc" label="macros" insertbeforeq="mso:tabhome">.... , information custom ribbon created in excel appear way </mso:tab>
so want take between <mso:tab id=".... </mso:tab> , copy "excel.officeui" file on local workstation, , enter right before </mso:tabs> (the final tag tabs) don't disrupt custom ribbons might have created.
if still following me here, thank patience :)
so here code i'm trying use reason, not find text i'm looking , might have way i'm entering "-pattern ..." portion or fact file might have multiple locations <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 simple i'm missing!
thank you!
alex
it xml. use xml locate , copy element.
you not ble reliably string methods.
$node=$xml.selectnode('//mso:tab[@id="mso_c2.3ed4dc"]')
$node.innertext = $newtext
$xml.save($filename)
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment