Avatar of Aakash Aggarwal
Aakash Aggarwal
 asked on

Edit multiple xmls in different folders

All the folders in screenshot are created by copying and renaming one Template folder. Now all sub-folders contains one xml file, need to update the path in these xml's with the path of Crystal Reports and DocMan folder, which exist in all these folders.

[xml]$XmlDocument = Get-Content -Path d:\Site\"$($name)\$($name).xml"
$XmlDocument.breakfast_menu.food.DocMan = 'd:\Site\'
$XmlDocument.breakfast_menu.food.Crystalreports = 'd:\Site\'
$XmlDocument.Save("D:\Site\"$($name)\$($name).xml")

The above script is not giving the desired result.

My earlier script for copying and renaming:
$source = 'd:\Site\Template'
$target = 'd:\Site\'
$xmlPath = 'D:\Tenant.xml'

$xml = [xml](Get-Content -Path $xmlPath)
$envCode = $xml.SelectSingleNode('Tenants/ENVcode').InnerText.Trim()
$xml.SelectNodes('Tenants/Schools/School') | ForEach-Object {
      $name = "$($envCode)-$($_.InnerText.Trim())"
      $destination = Join-Path -Path $target -ChildPath $name
      Copy-Item -Path $source -Destination $destination -Recurse -Force -Verbose
      Get-ChildItem -Path $destination -Filter default.xml -Recurse | Rename-Item -NewName "$($name).xml"      
}
Screenshot.png
PowershellXML

Avatar of undefined
Last Comment
Michael B. Smith

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Michael B. Smith

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck