I would like to fix some xml files seperated on multiple sites and document libraries in powershell. I have in a csv file the url of all these xml documents. So I already have some loop for each xml path. But how can I modify the content of these xml files? Do I need to download the file, modify it local and upload it again?

1 Answer 1


Yes, we need to download the XML file and update as per your need then upload back to the same location:

For update sample, you can refer the below PowerShell:

$Path = "\\spsite\sites\subsite\Library\"
$Files = Get-ChildItem $Path | where {$_.extension -eq ".xml"}
foreach($file in $Files){
    $xml = New-Object XML
    $xml.PreserveWhitespace = $true
    $xml.myFields.PhoneNumber = "234-5678"//update your fields on the form


Powershell to replace text in infopath XML files


If your XML files are relatively smaller in size - then you may use the MemoryStream - MemoryStream sample as below:

$Stream = New-Object System.IO.MemoryStream


Using powershell to read/modify/rewrite sharepoint xml document

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.