I have an XML file content similar to the following:
<?xml version="1.0" encoding="utf-8"?>
<Content>
<FileID>109F2AEA-6D9C-4127-963A-9C71D4155C5D</FileID>
<File Path="C:\test.config">
<Tag TagName="configuration">
<add Content="One" fileID="${FileID}"/>
<secondnode Content="Two" fileID="${FileID}">
<nodeinside>
<inneragain fileID="${FileID}"/>
</nodeinside>
</secondnode>
...
<diffentnode Content="Infinite" fileID="${FileID}"/>
</Tag>
</File>
</Content>
I just need to get this XML file content and edit (replacing whereever ${FileID} is present) the lines as shown below
<add fileID="${FileID}"/>
using the value of the "FileID" from the following line and get the output to a variable of DataType [xml].
<FileID>109F2AEA-6D9C-4127-963A-9C71D4155C5D</FileID>
Please suggest the best way this can be done in PowerShell.
code[CmdletBinding()] param ( [parameter(Mandatory=$true,ValueFromPipeline=$true)] [string[]]$ReplaceFile ); [xml]$ReplaceFileContent = Get-Content $ReplaceFile; $FileID = $ReplaceFileContent.Content.FileID; [String]$ReplaceFileContentString = Get-Content $ReplaceFile; $newReplaceFileContentString = $ReplaceFileContentString.Replace("${FileID}", $FileID); [xml]$newReplaceFileContent = [xml]$newReplaceFileContentString;code`