PowerShell - Update Same ElementTag in many XML files using PowerShell

If you want to update the same ElementTag in many xml files, below is the PowerShell code.


$location = "Specify your location here"
$items = Get-ChildItem -Path $location
foreach ($item in $items)
{
      # if the item is a directory, then process it.
      if ($item.Attributes -ne "directory")
      {
            if ($item.Extension -eq ".xml")
            {
                Write-Host $item.Name
                $file = $location + "\" + $item.Name
                $file = $item.Name
                $xml = New-Object XML 
                $xml.Load($file)
                $xml.ProjectDescription.ChildNodes.Item(0)."#text" = "Value updated by Powershell"
                $xml.Save($file)
            }
      }
}

No comments:

Post a Comment