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

Popular posts from this blog

2008 Windows Deployment Server Properties Error

Can no longer user MS Update - Files required to use Microsoft Update are no longer registered

How do a find data in one file, search for it in another file and if not found, write a custom message to another file