Can anyone explain me why I can get data from the xml file if I use this:
[xml]$configXml = Get-Content -Path "c:\test.xml"
$configXml.Config.Client.Servers.Server.name
Output: srv1
But if I use it inside a module, I get no data at all:
[xml]$configXml = Get-Content -Path "c:\test.xml"
function global:XTR_GetXmlConfig{
Param(
[Parameter(Mandatory=$true)]
$Option
)
return $configXml.Config.$Option
}
XTR_GetXmlConfig -Option Client.Servers.Server.name
only the first node retrives data using the module:
XTR_GetXmlConfig -Option Client
My xml is very basic:
?xml version="1.0" encoding="UTF-8"?>
<Config>
<Client>
<Domain>test.pt</Domain>
<Servers>
<Server>
<Name>srv1<Name>
<IP>192.168.0.1</IP>
</Server>
<Server>
<Name>srv2</Name>
<IP>192.168.0.2</IP>
</Server>
<Server>
<Name>srv3</Name>
<IP>192.168.0.3</IP>
</Server>
</Servers>
</Client>
</Config>
/character. There should also be a<as the first character of the file.