Author Posts

May 29, 2018 at 9:18 am

Please Help out With Powershell Script for :

1. Delete Specific “ ” node in Config-B.xml
2. Read specific “” node from Confi-A.xml.
3. Append in config-B.xml with step 2 out value.

Config-A.xml

Config-B.xml



#################### Get Source XML  Node Value ##########################

$CustomWinClientConfigXmlSource = "SourcePath\Config.xml"

[xml]$SourceConfigXml = Get-Content -Path "$CustomWinClientConfigXmlSource" -Raw
$SourceXmlNode = $SourceConfigXml | Select-Xml -XPath "//Section[@Name='APILibraries']"
$SourceXmlOutput = Write-Output "$SourceXmlNode"
$SourceXMLNodeValue = "$SourceXmlOutput"




#################### Get The Target XML  Node Value And Delete It ##############

$WinClientConfigFiles = "Config.xml"
$CustomWinClientConfigXmlTarget = "TargetPath\$WinClientConfigFiles"

$Path = "$CustomWinClientConfigXmlTarget"

[Xml]$servicefactoryconfig = Get-Content -Path $Path -Raw

$old = $servicefactoryconfig.SelectSingleNode("/Configuration/Data/Section[@Name='APILibraries']")

$parent = $old.ParentNode

[void] $parent.RemoveChild($old)


################################# Append The Target XML  With Source XML Node Value ###########

Try

{

$newNode = [Xml] @"
$SourceXMLNodeValue
"@

}

Catch

{

Write-Error -Message 'Ignoring The Error Message' -ErrorAction Ignore

}

[void] $parent.AppendChild($servicefactoryconfig.ImportNode($newNode.DocumentElement,$true))

$servicefactoryconfig.save($path)

May 30, 2018 at 2:52 am

Unfortunately you can't paste XML here. You'll need to post that as a Gist, and include a URL to the Gist here.

However, although you're clearly programming in PowerShell, you're *really* using the underlying .NET Framework. You might get a better and quicker response on a site like StackOverflow.com, where there's a much larger audience of developers also working directly with .NET.

May 30, 2018 at 9:55 am

Hi,

Thanks for your suggestion. Yes , i have got the help and it worked for me.
I will stay in touch for various post on this community.

Thanks
Vivek