Can't prevent PowerShell from changing the return object's type

Viewed 325

When I am returning XML object from a function, PowerShell is changing its type to Object[]:

enter image description here

I read here:
PowerShell changes return object's type
Preserving PowerShell function return type
https://www.experts-exchange.com/questions/27035513/How-to-stop-PowerShell-function-changing-return-type-of-ArrayList-or-string.html

How to prevent it and all of them wrote that adding comma , in the return should solve it.

I tried:

return ,$computer

The problem still exist.
It still returns me Object[] type instead of XmlElement type.

Example code:

Function getComputerXML($doc){
    $computer  = $doc.CreateNode("element","Computer",$null)

    $computerSettings = $doc.CreateNode("element","ComputerSettings",$null)
    $computerSettings.SetAttribute("Name","HP") | Out-Null
    $computerSettings.InnerText = "someText"
    $computer.AppendChild($computerSettings)

    return $computer
}

Function main(){

   [xml]$doc = New-Object System.Xml.XmlDocument

   $computer = getComputerXML $doc
   #$computers.AppendChild($computer)
}

main
1 Answers
Related