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
LVL 1
Aakash AggarwalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael B. SmithManaging ConsultantCommented:
If I understand properly, this should do it for you:
$folders = dir c:\site -directory
foreach( $folder in $folders )
{
	$xmlFile = Join-Path $folder.FullName ( $folder.Name + '.xml' )
	if( Test-Path $xmlFile )
	{
		[xml]$xml = Get-Content $xmlFile
		[string]$docman  = Join-Path $folder.FullName 'DocMan'
		[string]$crystal = Join-Path $folder.FullName 'Crystal reports'
		$xml.breakfast_menu.food.DocMan = $docman
		$xml.breakfast_menu.food.Crystalreports = $crystal
		$xml.breakfast_menu.food.DocMan
		$xml.breakfast_menu.food.Crystalreports
		$xml.Save( $xmlFile )
	}
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.