I have created a simple powershell script (replacer.ps1), which:
- Reads a xml file
- Changes one of the attributes
- Saves file
The code of replacer.ps1 is as follows:
function ReplaceElemInXml
{
param ([string]$xmlFilePath)
[xml]$xmlContent = Get-Content -Path $xmlFilePath
$element = $xmlContent.SelectSingleNode("//aa")
$element.SetAttribute("checksum", "newAttributeValue")
$xmlContent.Save($xmlFilePath)
Write-Output "Attribute updated successfully for file: $xmlFilePath "
}
ReplaceElemInXml -xmlFilePath "test.xml"
the structure of my folder is:
After I run the code from the commandline in IntelliJ:
> attributeReplacer\childFolder\onemoreChildFolder> .\replacer.ps1
The output says:
Attribute updated successfully for file: test.xml
But the original test.xml file is not being updated, instead a new test.xml file is being created in the root folder of IntelliJ project:
How can I overwrite the file in the current folder?