Using Powershell, I want to make changes in XML file and the files that need change 0 to ${ThinkTime} for the name RandomTimer.range in multiple places.
I want to check if 0 is present before replace.
XML message:
<UniformRandomTimer guiclass="UniformRandomTimerGui" testclass="UniformRandomTimer" testname="Think Time" enabled="true">
<stringProp name="ConstantTimer.delay">${ThinkTime}</stringProp>
<stringProp name="RandomTimer.range">0</stringProp>
</UniformRandomTimer>
Below Powershell script is not working as expected:
Get-ChildItem -Path C:\Users**\Desktop\Projects**\D****\scripts*.jmx | ForEach-Object {
$xmlDocument = [xml]($_ |Get-Content)
$tmConfig = $xmlDocument.SelectSingleNode("//UniformRandomTimer/stringProp[2]")
# attribute exists, let's update it!
if($tmConfig.GetAttribute('#text') -eq "0") {
$tmConfig.SetAttribute("#text", "${ThinkTime}")
}
$xmlDocument.Save($_.FullName)
}