I have a project to create a script to handle our Lync provisioning – trying to keep it as modular as possible. I think this works best by keeping each script file in its own directory, with its own ‘scopedConfig’ & a ‘centralXML’ with tags that are globally useful.
The problem I have is when trying to import 2 XML files consecutively using Get-content.
The code I have is:
# Import CentralConfig
[xml]$centralXML = Get-content ".\centralConfig.xml"
# Import ScopedConfig
[xml]$scopedXML = Get-content ".\ExecutionResources\ScopedConfigfiles\HostConsole\config.xml"
I’m testing successful import with the following:
"------------------"
"------------------"
$centralXML
"------------------"
$scopedXML
"------------------"
"------------------"
The result and where the issue lies is the output:
------------------
------------------
Global_ConfigRoot
-----------------
Global_ConfigRoot
------------------
------------------
------------------
I expected the root nodes of both XMLs as output, instead I only get the root node of the first. If I swap it round so that $scopedXML is first – I only get $scopedXML root node and nothing from $centralXML.
An interesting thing to note is that if I pipe the 2nd XML to Get-member – where you’d usually expect to see all XML related things and it’s properties, I get a whole load of blankness:
------------------
------------------
Global_ConfigRoot
-----------------
Global_ConfigRoot
------------------
------------------
------------------
I have never come across this before, does anyone have any suggestions?
(PS Tried my best to keep to the posting rules, let me know if anything is wrong it’s my first time posting here)
A function, cmdlet or script can only return AN object. It you return mulitple like you do by calling both variables, it actually returns an
object[]array containing both items (+ the lines you printed). The objects are untouched and just added to this collection.Now, when your script outputs(displays) the object that was returned, it formats it as a table since there were multiple objects inside. A table can only contain 1 header(column-names), and when displaying an array, it takes the columns(properties) from the first item, in this case
$centralxml. That’s why you get 2 columns: xml and servers.If you want to seperate them you have to tell the script to format them in seperate tables. Ex: